Skip to content

Commit

Permalink
Remove explicit WriteHeader call to have correct content type
Browse files Browse the repository at this point in the history
According to the documentation:

    // WriteHeader sends an HTTP response header with status code.
    // If WriteHeader is not called explicitly, the first call to Write
    // will trigger an implicit WriteHeader(http.StatusOK).
    // Thus explicit calls to WriteHeader are mainly used to
    // send error codes.

and

    // Header returns the header map that will be sent by WriteHeader.
    // Changing the header after a call to WriteHeader (or Write) has
    // no effect.

so calling `w.Header().Set(contentType, jsonContentType)` after calling
`w.WriteHeader` does not set the content type -- the call can be removed
though as it always set `http.StatusOK` which will be done anyways
  • Loading branch information
Daniel Bornkessel committed Jan 3, 2013
1 parent 474d1d5 commit 05891fd
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (registry *Registry) YieldExporter() http.HandlerFunc {
url := r.URL

if strings.HasSuffix(url.Path, jsonSuffix) {
w.WriteHeader(http.StatusOK)
w.Header().Set(contentType, jsonContentType)
composite := make(map[string]interface{}, len(registry.NameToMetric))
for name, metric := range registry.NameToMetric {
Expand Down

0 comments on commit 05891fd

Please sign in to comment.