MCPcopy
hub / github.com/willnorris/imageproxy / ServeHTTP

Method ServeHTTP

imageproxy.go:200–224  ·  view source on GitHub ↗

ServeHTTP handles incoming requests.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

198
199// ServeHTTP handles incoming requests.
200func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
201 if r.URL.Path == "/favicon.ico" {
202 return // ignore favicon requests
203 }
204
205 if r.URL.Path == "/" || r.URL.Path == "/health-check" {
206 fmt.Fprint(w, "OK")
207 return
208 }
209
210 if r.URL.Path == "/metrics" {
211 var h = promhttp.Handler()
212 h.ServeHTTP(w, r)
213 return
214 }
215
216 var h http.Handler = http.HandlerFunc(p.serveImage)
217 if p.Timeout > 0 {
218 h = tphttp.TimeoutHandler(h, p.Timeout, "Gateway timeout waiting for remote resource.")
219 }
220
221 timer := prometheus.NewTimer(metricRequestDuration)
222 defer timer.ObserveDuration()
223 h.ServeHTTP(w, r)
224}
225
226// serveImage handles incoming requests for proxied images.
227func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {

Callers 4

TestProxy_ServeHTTPFunction · 0.95

Calls

no outgoing calls

Tested by 4

TestProxy_ServeHTTPFunction · 0.76