MCPcopy
hub / github.com/esm-dev/esm.sh / FetchWithContext

Method FetchWithContext

internal/fetch/fetch.go:40–60  ·  view source on GitHub ↗

FetchWithContext sends an HTTP GET request with cancellation support.

(ctx context.Context, url *url.URL, header http.Header)

Source from the content-addressed store, hash-verified

38
39// FetchWithContext sends an HTTP GET request with cancellation support.
40func (c *FetchClient) FetchWithContext(ctx context.Context, url *url.URL, header http.Header) (resp *http.Response, err error) {
41 if ctx == nil {
42 ctx = context.Background()
43 }
44 if c.userAgent != "" {
45 if header == nil {
46 header = make(http.Header)
47 }
48 header.Set("User-Agent", c.userAgent)
49 }
50 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
51 if err != nil {
52 return nil, err
53 }
54 req.Host = url.Host
55 req.Proto = "HTTP/1.1"
56 req.ProtoMajor = 1
57 req.ProtoMinor = 1
58 req.Header = header
59 return c.Do(req)
60}

Callers 4

FetchMethod · 0.95
ghInstallContextFunction · 0.80

Calls 2

SetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected