ServeHTTP handles incoming requests.
(w http.ResponseWriter, r *http.Request)
| 198 | |
| 199 | // ServeHTTP handles incoming requests. |
| 200 | func (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. |
| 227 | func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) { |
no outgoing calls