nghttpx: Return 501 if invalid method is received on h1 frontend

This commit is contained in:
Tatsuhiro Tsujikawa 2015-06-09 22:08:49 +09:00
parent c2ca04c1db
commit f9c60d5e9d
2 changed files with 24 additions and 1 deletions

View File

@ -52,6 +52,27 @@ func TestH1H1PlainGETClose(t *testing.T) {
}
}
// TestH1H1InvalidMethod tests that server rejects invalid method with
// 501 status code
func TestH1H1InvalidMethod(t *testing.T) {
st := newServerTester(nil, t, func(w http.ResponseWriter, r *http.Request) {
t.Errorf("server should not forward this request")
})
defer st.Close()
res, err := st.http1(requestParam{
name: "TestH1H1InvalidMethod",
method: "get",
})
if err != nil {
t.Fatalf("Error st.http1() = %v", err)
}
if got, want := res.status, 501; got != want {
t.Errorf("status = %v; want %v", got, want)
}
}
// TestH1H1MultipleRequestCL tests that server rejects request which
// contains multiple Content-Length header fields.
func TestH1H1MultipleRequestCL(t *testing.T) {

View File

@ -460,7 +460,9 @@ int HttpsUpstream::on_read() {
unsigned int status_code;
if (downstream) {
if (htperr == HPE_INVALID_METHOD) {
status_code = 501;
} else if (downstream) {
if (downstream->get_request_state() == Downstream::CONNECT_FAIL) {
status_code = 503;
} else if (downstream->get_request_state() ==