From 0647012449a1878977514a346b26637dd022446c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Feb 2018 12:30:15 +0900 Subject: [PATCH] Modify http status code to variable --- client_server_test.go | 14 +++++++------- examples/autobahn/server.go | 4 ++-- examples/chat/main.go | 4 ++-- examples/command/main.go | 4 ++-- examples/filewatch/main.go | 4 ++-- server.go | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client_server_test.go b/client_server_test.go index 50063b7..dcaab3d 100644 --- a/client_server_test.go +++ b/client_server_test.go @@ -72,18 +72,18 @@ func newTLSServer(t *testing.T) *cstServer { func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.URL.Path != cstPath { t.Logf("path=%v, want %v", r.URL.Path, cstPath) - http.Error(w, "bad path", 400) + http.Error(w, "bad path", http.StatusBadRequest) return } if r.URL.RawQuery != cstRawQuery { t.Logf("query=%v, want %v", r.URL.RawQuery, cstRawQuery) - http.Error(w, "bad path", 400) + http.Error(w, "bad path", http.StatusBadRequest) return } subprotos := Subprotocols(r) if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) { t.Logf("subprotols=%v, want %v", subprotos, cstDialer.Subprotocols) - http.Error(w, "bad protocol", 400) + http.Error(w, "bad protocol", http.StatusBadRequest) return } ws, err := cstUpgrader.Upgrade(w, r, http.Header{"Set-Cookie": {"sessionID=1234"}}) @@ -160,13 +160,13 @@ func TestProxyDial(t *testing.T) { func(w http.ResponseWriter, r *http.Request) { if r.Method == "CONNECT" { connect = true - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) return } if !connect { t.Log("connect not received") - http.Error(w, "connect not received", 405) + http.Error(w, "connect not received", http.StatusMethodNotAllowed) return } origHandler.ServeHTTP(w, r) @@ -200,13 +200,13 @@ func TestProxyAuthorizationDial(t *testing.T) { expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")) if r.Method == "CONNECT" && proxyAuth == expectedProxyAuth { connect = true - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) return } if !connect { t.Log("connect with proxy authorization not received") - http.Error(w, "connect with proxy authorization not received", 405) + http.Error(w, "connect with proxy authorization not received", http.StatusMethodNotAllowed) return } origHandler.ServeHTTP(w, r) diff --git a/examples/autobahn/server.go b/examples/autobahn/server.go index 3db880f..c2d6ee5 100644 --- a/examples/autobahn/server.go +++ b/examples/autobahn/server.go @@ -157,11 +157,11 @@ func echoReadAllWritePreparedMessage(w http.ResponseWriter, r *http.Request) { func serveHome(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { - http.Error(w, "Not found.", 404) + http.Error(w, "Not found.", http.StatusNotFound) return } if r.Method != "GET" { - http.Error(w, "Method not allowed", 405) + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") diff --git a/examples/chat/main.go b/examples/chat/main.go index 74615d5..9d4737a 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -15,11 +15,11 @@ var addr = flag.String("addr", ":8080", "http service address") func serveHome(w http.ResponseWriter, r *http.Request) { log.Println(r.URL) if r.URL.Path != "/" { - http.Error(w, "Not found", 404) + http.Error(w, "Not found", http.StatusNotFound) return } if r.Method != "GET" { - http.Error(w, "Method not allowed", 405) + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } http.ServeFile(w, r, "home.html") diff --git a/examples/command/main.go b/examples/command/main.go index 239c5c8..304f1a5 100644 --- a/examples/command/main.go +++ b/examples/command/main.go @@ -167,11 +167,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) { func serveHome(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { - http.Error(w, "Not found", 404) + http.Error(w, "Not found", http.StatusNotFound) return } if r.Method != "GET" { - http.Error(w, "Method not allowed", 405) + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } http.ServeFile(w, r, "home.html") diff --git a/examples/filewatch/main.go b/examples/filewatch/main.go index f5f9da5..b834ed3 100644 --- a/examples/filewatch/main.go +++ b/examples/filewatch/main.go @@ -130,11 +130,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) { func serveHome(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { - http.Error(w, "Not found", 404) + http.Error(w, "Not found", http.StatusNotFound) return } if r.Method != "GET" { - http.Error(w, "Method not allowed", 405) + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") diff --git a/server.go b/server.go index 50b58a8..3e96a00 100644 --- a/server.go +++ b/server.go @@ -243,7 +243,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade // of the same origin policy check is: // // if req.Header.Get("Origin") != "http://"+req.Host { -// http.Error(w, "Origin not allowed", 403) +// http.Error(w, "Origin not allowed", http.StatusForbidden) // return // } //