Fix error getting HTTP version in getRequestVersion
This commit is contained in:
@@ -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) {
|
func getRequestVersion(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
w.Header().Add("Content-Type", "application/octet-stream")
|
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) {
|
func getRequestPath(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
|
|||||||
@@ -275,14 +275,17 @@ func TestGetRequestVersionReturnsTheCorrectHttpVersion(t *testing.T) {
|
|||||||
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
|
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
|
||||||
Writer: httptest.NewRecorder(),
|
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)
|
r := httptest.NewRequest("GET", "/not-important-here", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
getRequestVersion(w, r, &h)
|
getRequestVersion(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "HTTP/1.1" {
|
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.Proto {
|
||||||
t.Errorf("Version mismatch. Expected %v, got %v", "HTTP/1.1", string(body))
|
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.Proto, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user