Skip to content

Commit

Permalink
oops, add a missing WriteHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed Apr 12, 2024
1 parent 53f9bb6 commit 5ccde39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
3 changes: 2 additions & 1 deletion jsv1/version1.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const lengthOfJavaScript = "17"
func Write(w http.ResponseWriter, code int) {
w.Header().Set("Content-Type", "application/javascript")
w.Header().Set("Content-Length", lengthOfJavaScript)

// Note: All w.Header() modifications must be made BEFORE this call.
w.WriteHeader(code)
fmt.Fprintf(w, returnedJavaScript)
}

Expand Down
10 changes: 2 additions & 8 deletions pingv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ func TestPingV2_Success(t *testing.T) {
handler := NewHandler([]string{"example.org"}, "")
handler.ServeHTTP(recorder, request)

if status := recorder.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusCreated)
}
assertStatusCode(t, recorder, http.StatusOK)

expected := "function logVisit"
if !strings.Contains(recorder.Body.String(), expected) {
Expand Down Expand Up @@ -339,10 +336,7 @@ func TestSubmitV2_Success_PreservesXForwardedForOverRemoteAddr(t *testing.T) {
handler := NewHandler([]string{"example.org"}, "")
handler.ServeHTTP(recorder, request)

if status := recorder.Code; status != http.StatusCreated {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusCreated)
}
assertStatusCode(t, recorder, http.StatusCreated)

expected := "(function(){})();"
if recorder.Body.String() != expected {
Expand Down

0 comments on commit 5ccde39

Please sign in to comment.