Description
100 Continue response can be issued many times before an actual response is return (eg. 200 OK). In case of promhttp these responses should be ignored.
When you look at the http/server.go: https://github.com/golang/go/blob/go1.24.1/src/net/http/server.go#L1212-L1228 you can notice that they only set wroteHeader variable or status when it is not informational header.
But here https://github.com/prometheus/client_golang/blob/v1.21.1/prometheus/promhttp/delegator.go#L55-L66 we don't filter 100 Continue response.
Therefore, when 100 Continue is set and then there is no explicit 200 OK reported, then final status code will be 100 and not 200 as it should be.
Steps To Reproduce
- Use following handler:
targetHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusContinue) // Explicitly inform client that we are ready for body.
body, _ := io.ReadAll(r.Body)
w.Write(body)
})
http.Handle("/target", promhttp.InstrumentHandlerResponseSize(metric, targetHandler))
- Run the code.
- Handler will report
100 Continue header as final status code instead of 200 OK.
Expected behavior
200 OK status code to be reported even when there is explicit 100 Continue done in the handler.
Likely we need to do similar thing that they do in http/server.go which is to simply ignore informational headers if they are issued before a regular response.
Description
100 Continueresponse can be issued many times before an actual response is return (eg.200 OK). In case ofpromhttpthese responses should be ignored.When you look at the
http/server.go: https://github.com/golang/go/blob/go1.24.1/src/net/http/server.go#L1212-L1228 you can notice that they only setwroteHeadervariable orstatuswhen it is not informational header.But here https://github.com/prometheus/client_golang/blob/v1.21.1/prometheus/promhttp/delegator.go#L55-L66 we don't filter
100 Continueresponse.Therefore, when
100 Continueis set and then there is no explicit200 OKreported, then final status code will be100and not200as it should be.Steps To Reproduce
100 Continueheader as final status code instead of200 OK.Expected behavior
200 OKstatus code to be reported even when there is explicit100 Continuedone in the handler.Likely we need to do similar thing that they do in
http/server.gowhich is to simply ignore informational headers if they are issued before a regular response.