MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / BuildRequest

Method BuildRequest

fetcher/fetcher.go:38–72  ·  view source on GitHub ↗

BuildRequest creates a new [Request] with the provided context, URL, headers, and cookie jar

(
	ctx context.Context, url string, header http.Header, jar http.CookieJar,
)

Source from the content-addressed store, hash-verified

36
37// BuildRequest creates a new [Request] with the provided context, URL, headers, and cookie jar
38func (f *Fetcher) BuildRequest(
39 ctx context.Context, url string, header http.Header, jar http.CookieJar,
40) (*Request, error) {
41 url = transport.EscapeURL(url)
42
43 // Set request timeout and get cancel function
44 ctx, cancel := context.WithTimeout(ctx, f.config.DownloadTimeout)
45
46 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
47 if err != nil {
48 cancel()
49 return nil, newRequestError(err)
50 }
51
52 // Check if the URL scheme is supported
53 if !f.transport.IsProtocolRegistered(req.URL.Scheme) {
54 cancel()
55 return nil, newRequestSchemeError(req.URL.Scheme)
56 }
57
58 // Add cookies from the jar to the request (if any)
59 if jar != nil {
60 for _, cookie := range jar.Cookies(req.URL) {
61 req.AddCookie(cookie)
62 }
63 }
64
65 // Set user agent header
66 req.Header.Set(httpheaders.UserAgent, f.config.UserAgent)
67
68 // Set headers
69 httpheaders.CopyToRequest(header, req)
70
71 return &Request{f, req, cancel}, nil
72}
73
74// checkRedirect is a method that checks if the number of redirects exceeds the maximum allowed
75func (f *Fetcher) checkRedirect(req *http.Request, via []*http.Request) error {

Callers 2

executeMethod · 0.80
sendRequestMethod · 0.80

Calls 7

EscapeURLFunction · 0.92
CopyToRequestFunction · 0.92
newRequestErrorFunction · 0.85
newRequestSchemeErrorFunction · 0.85
IsProtocolRegisteredMethod · 0.80
CookiesMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected