forked from mirror/client_golang
Merge "Add Content-Length header."
This commit is contained in:
commit
457bc47eac
|
@ -75,6 +75,7 @@ const (
|
||||||
capDescChan = 10
|
capDescChan = 10
|
||||||
|
|
||||||
contentTypeHeader = "Content-Type"
|
contentTypeHeader = "Content-Type"
|
||||||
|
contentLengthHeader = "Content-Length"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handler returns the HTTP handler for the global Prometheus registry. It is
|
// Handler returns the HTTP handler for the global Prometheus registry. It is
|
||||||
|
@ -353,7 +354,7 @@ func (r *registry) Push(job, instance, addr, method string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest(method, u, buf)
|
req, err := http.NewRequest(method, u, buf)
|
||||||
req.Header.Set("Content-Type", DelimitedTelemetryContentType)
|
req.Header.Set(contentTypeHeader, DelimitedTelemetryContentType)
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -369,7 +370,6 @@ func (r *registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
enc, contentType := chooseEncoder(req)
|
enc, contentType := chooseEncoder(req)
|
||||||
buf := r.getBuf()
|
buf := r.getBuf()
|
||||||
defer r.giveBuf(buf)
|
defer r.giveBuf(buf)
|
||||||
header := w.Header()
|
|
||||||
if _, err := r.writePB(buf, enc); err != nil {
|
if _, err := r.writePB(buf, enc); err != nil {
|
||||||
if r.panicOnCollectError {
|
if r.panicOnCollectError {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -377,7 +377,9 @@ func (r *registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
http.Error(w, "An error has occurred:\n\n"+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "An error has occurred:\n\n"+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
header := w.Header()
|
||||||
header.Set(contentTypeHeader, contentType)
|
header.Set(contentTypeHeader, contentType)
|
||||||
|
header.Set(contentLengthHeader, fmt.Sprint(buf.Len()))
|
||||||
w.Write(buf.Bytes())
|
w.Write(buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue