Skip to content

Commit

Permalink
Fix error getting HTTP version in getRequestVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
Héctor Hurtado committed Sep 10, 2020
1 parent 99871de commit 66b227e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/server/data/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getRequestHost(w http.ResponseWriter, r *http.Request, h *model.Handler) {

func getRequestVersion(w http.ResponseWriter, r *http.Request, h *model.Handler) {
w.Header().Add("Content-Type", "application/octet-stream")
_, _ = w.Write([]byte(r.Proto))
_, _ = w.Write([]byte(h.Request.Proto))
}

func getRequestPath(w http.ResponseWriter, r *http.Request, h *model.Handler) {
Expand Down
7 changes: 5 additions & 2 deletions internal/server/data/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,17 @@ func TestGetRequestVersionReturnsTheCorrectHttpVersion(t *testing.T) {
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
Writer: httptest.NewRecorder(),
}
h.Request.Proto = "HTTP/1.0"
h.Request.ProtoMajor = 1
h.Request.ProtoMinor = 0
r := httptest.NewRequest("GET", "/not-important-here", nil)
w := httptest.NewRecorder()

getRequestVersion(w, r, &h)

res := w.Result()
if body, _ := ioutil.ReadAll(res.Body); string(body) != "HTTP/1.1" {
t.Errorf("Version mismatch. Expected %v, got %v", "HTTP/1.1", string(body))
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.Proto {
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.Proto, string(body))
}
}

Expand Down

0 comments on commit 66b227e

Please sign in to comment.