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

Method sendRequest

imagedata/factory.go:197–245  ·  view source on GitHub ↗

sendRequest is a common logic between sync and async download.

(
	ctx context.Context, url string, opts DownloadOptions,
)

Source from the content-addressed store, hash-verified

195
196// sendRequest is a common logic between sync and async download.
197func (f *Factory) sendRequest(
198 ctx context.Context, url string, opts DownloadOptions,
199) (*fetcher.Request, *http.Response, http.Header, error) {
200 h := make(http.Header)
201
202 // NOTE: This will be removed in the future when our test context gets better isolation
203 if len(redirectAllRequestsTo) > 0 {
204 url = redirectAllRequestsTo
205 }
206
207 header := opts.Header
208
209 // Inject monitoring headers.
210 // Clone the headers to avoid modifying the original ones.
211 if f.monitoring != nil {
212 header = header.Clone()
213 f.monitoring.InjectHeaders(ctx, header)
214 }
215
216 req, err := f.fetcher.BuildRequest(ctx, url, header, opts.CookieJar)
217 if err != nil {
218 return req, nil, h, err
219 }
220
221 res, err := req.Fetch()
222 if res != nil {
223 h = res.Header.Clone()
224 }
225 if err != nil {
226 if res != nil {
227 res.Body.Close()
228 }
229 req.Cancel()
230
231 return req, nil, h, err
232 }
233
234 res, err = limitResponseSize(res, opts.MaxSrcFileSize)
235 if err != nil {
236 if res != nil {
237 res.Body.Close()
238 }
239 req.Cancel()
240
241 return req, nil, h, err
242 }
243
244 return req, res, h, nil
245}
246
247func (f *Factory) startMonitoringSpan(
248 ctx context.Context,

Callers 2

DownloadSyncMethod · 0.95
DownloadAsyncMethod · 0.95

Calls 7

limitResponseSizeFunction · 0.85
BuildRequestMethod · 0.80
FetchMethod · 0.80
CancelMethod · 0.80
InjectHeadersMethod · 0.65
CloseMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected