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

Method execute

handlers/stream/handler.go:94–143  ·  view source on GitHub ↗

execute handles the actual streaming logic

()

Source from the content-addressed store, hash-verified

92
93// execute handles the actual streaming logic
94func (s *request) execute() *server.Error {
95 s.Monitoring().Stats().IncImagesInProgress()
96 defer s.Monitoring().Stats().DecImagesInProgress()
97
98 ctx, cancelSpan := s.Monitoring().StartSpan(s.imageRequest.Context(), "Streaming image", nil)
99 defer cancelSpan()
100
101 // Passthrough request headers from the original request
102 requestHeaders := s.getImageRequestHeaders()
103 cookieJar, err := s.getCookieJar()
104 if err != nil {
105 return s.wrapError(err)
106 }
107
108 // Build the request to fetch the image
109 r, err := s.Fetcher().BuildRequest(ctx, s.imageURL, requestHeaders, cookieJar)
110 if r != nil {
111 defer r.Cancel()
112 }
113 if err != nil {
114 return s.wrapError(err)
115 }
116
117 // Send the request to fetch the image
118 res, err := r.Send()
119 if res != nil {
120 defer res.Body.Close()
121 }
122 if err != nil {
123 return s.wrapError(err)
124 }
125
126 // Output streaming response headers
127 s.rw.SetOriginHeaders(res.Header)
128 s.rw.Passthrough(s.handler.config.PassthroughResponseHeaders...) // NOTE: priority? This is lowest as it was
129 s.rw.SetContentLength(int(res.ContentLength))
130 s.rw.SetCanonical(s.imageURL)
131 s.rw.SetExpires(s.opts.GetTime(keys.Expires))
132
133 // Set the Content-Disposition header
134 s.setContentDisposition(r.URL().Path, res)
135
136 // Copy the status code from the original response
137 s.rw.WriteHeader(res.StatusCode)
138
139 // Write the actual data
140 s.streamData(res)
141
142 return nil
143}
144
145// getCookieJar returns non-empty cookie jar if cookie passthrough is enabled
146func (s *request) getCookieJar() (http.CookieJar, error) {

Callers 1

ExecuteMethod · 0.95

Calls 15

getCookieJarMethod · 0.95
wrapErrorMethod · 0.95
setContentDispositionMethod · 0.95
streamDataMethod · 0.95
IncImagesInProgressMethod · 0.80
StatsMethod · 0.80
DecImagesInProgressMethod · 0.80
BuildRequestMethod · 0.80
CancelMethod · 0.80
SendMethod · 0.80
PassthroughMethod · 0.80

Tested by

no test coverage detected