Skip to content

Commit

Permalink
use statWriter in ClientInfo handler
Browse files Browse the repository at this point in the history
Now that we don't rely on hijack, we can use the statWriter to write our
metrics.

This probably would be better a deeper integration of our tracing work,
but this at least makes the metrics consistent.

Updates #530
  • Loading branch information
jmhodges committed Jul 9, 2023
1 parent d32b6b9 commit a008de2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions howsmyssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,19 @@ func hijackHandle(w http.ResponseWriter, r *http.Request, statuses *statusStats,
// request. We do this smuggling instead of using http.Hijcker.Hijack to
// avoid needing to do a bunch of connection management and HTTP response
// formatting ourselves.
w = &statWriter{w: w, stats: statuses}
c := r.Context().Value(smuggledConnKey)
tc, ok := c.(*conn)
if !ok {
log.Printf("Unable to convert smuggledConnKey to *conn: %#v\n", c)
response500(w, r, statuses)
response500(w, r)
return
}
data := pullClientInfo(tc)
bs, status, contentType, err := render(r, data)
if err != nil {
log.Printf("Unable to execute render: %s\n", err)
response500(w, r, statuses)
response500(w, r)
return
}
defaultResponseHeaders(w.Header(), r, contentType)
Expand All @@ -441,7 +442,6 @@ func hijackHandle(w http.ResponseWriter, r *http.Request, statuses *statusStats,

// TODO(#524): this only increments 2xx when (in extremely hard to create
// circumstances) the render func could return other status codes.
statuses.status2xx.Add(1)
w.WriteHeader(status)
w.Write(bs)
}
Expand All @@ -452,7 +452,7 @@ func defaultResponseHeaders(h http.Header, r *http.Request, contentType string)
h.Set("Access-Control-Allow-Origin", "*")
}

func response500(w http.ResponseWriter, r *http.Request, statuses *statusStats) {
func response500(w http.ResponseWriter, r *http.Request) {
defaultResponseHeaders(w.Header(), r, "text/plain")
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("500 Internal Server Error"))
Expand Down

0 comments on commit a008de2

Please sign in to comment.