FetchWithContext sends an HTTP GET request with cancellation support.
(ctx context.Context, url *url.URL, header http.Header)
| 38 | |
| 39 | // FetchWithContext sends an HTTP GET request with cancellation support. |
| 40 | func (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 | } |
no test coverage detected