( ctx context.Context, query *Query, checksum dagql.Optional[dagql.String], permissions int, name string, )
| 228 | } |
| 229 | |
| 230 | func (state *HTTPState) Resolve( |
| 231 | ctx context.Context, |
| 232 | query *Query, |
| 233 | checksum dagql.Optional[dagql.String], |
| 234 | permissions int, |
| 235 | name string, |
| 236 | ) (_ *HTTPFetchResult, rerr error) { |
| 237 | state.mu.Lock() |
| 238 | defer state.mu.Unlock() |
| 239 | |
| 240 | expectedChecksum, err := parseOptionalChecksum(checksum) |
| 241 | if err != nil { |
| 242 | return nil, fmt.Errorf("invalid checksum %q: %w", checksum.Value, err) |
| 243 | } |
| 244 | |
| 245 | if state.snapshot == nil && state.snapshotID != "" { |
| 246 | snapshot, err := query.SnapshotManager().GetBySnapshotID(ctx, state.snapshotID, bkcache.NoUpdateLastUsed) |
| 247 | if err != nil { |
| 248 | return nil, fmt.Errorf("reopen http state snapshot %q: %w", state.snapshotID, err) |
| 249 | } |
| 250 | state.snapshot = snapshot |
| 251 | } |
| 252 | |
| 253 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, state.URL, nil) |
| 254 | if err != nil { |
| 255 | return nil, err |
| 256 | } |
| 257 | req.Header.Set("Accept-Encoding", "identity") |
| 258 | if state.ETag != "" { |
| 259 | req.Header.Set("If-None-Match", state.ETag) |
| 260 | } else if state.LastModified != "" { |
| 261 | req.Header.Set("If-Modified-Since", state.LastModified) |
| 262 | } |
| 263 | |
| 264 | dns, err := DNSConfig(ctx) |
| 265 | if err != nil { |
| 266 | return nil, err |
| 267 | } |
| 268 | client := http.Client{ |
| 269 | Transport: netconfhttp.NewTransport(http.DefaultTransport, dns), |
| 270 | } |
| 271 | resp, err := client.Do(req) |
| 272 | if err != nil { |
| 273 | return nil, err |
| 274 | } |
| 275 | defer resp.Body.Close() |
| 276 | if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNotModified { |
| 277 | return nil, fmt.Errorf("invalid response status %s", resp.Status) |
| 278 | } |
| 279 | |
| 280 | if resp.StatusCode == http.StatusNotModified { |
| 281 | if state.snapshot == nil { |
| 282 | return nil, fmt.Errorf("http state %q returned 304 without a cached snapshot", state.URL) |
| 283 | } |
| 284 | if etag := etagValue(resp.Header.Get("ETag")); etag != "" { |
| 285 | state.ETag = etag |
| 286 | } |
| 287 | if lastModified := resp.Header.Get("Last-Modified"); lastModified != "" { |
nothing calls this directly
no test coverage detected