mirror of https://github.com/gorilla/websocket.git
Modify http status code to variable
This commit is contained in:
parent
f37d158860
commit
0647012449
|
@ -72,18 +72,18 @@ func newTLSServer(t *testing.T) *cstServer {
|
||||||
func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != cstPath {
|
if r.URL.Path != cstPath {
|
||||||
t.Logf("path=%v, want %v", 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
|
return
|
||||||
}
|
}
|
||||||
if r.URL.RawQuery != cstRawQuery {
|
if r.URL.RawQuery != cstRawQuery {
|
||||||
t.Logf("query=%v, want %v", 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
|
return
|
||||||
}
|
}
|
||||||
subprotos := Subprotocols(r)
|
subprotos := Subprotocols(r)
|
||||||
if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) {
|
if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) {
|
||||||
t.Logf("subprotols=%v, want %v", 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
|
return
|
||||||
}
|
}
|
||||||
ws, err := cstUpgrader.Upgrade(w, r, http.Header{"Set-Cookie": {"sessionID=1234"}})
|
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) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "CONNECT" {
|
if r.Method == "CONNECT" {
|
||||||
connect = true
|
connect = true
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !connect {
|
if !connect {
|
||||||
t.Log("connect not received")
|
t.Log("connect not received")
|
||||||
http.Error(w, "connect not received", 405)
|
http.Error(w, "connect not received", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
origHandler.ServeHTTP(w, r)
|
origHandler.ServeHTTP(w, r)
|
||||||
|
@ -200,13 +200,13 @@ func TestProxyAuthorizationDial(t *testing.T) {
|
||||||
expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
|
expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
|
||||||
if r.Method == "CONNECT" && proxyAuth == expectedProxyAuth {
|
if r.Method == "CONNECT" && proxyAuth == expectedProxyAuth {
|
||||||
connect = true
|
connect = true
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !connect {
|
if !connect {
|
||||||
t.Log("connect with proxy authorization not received")
|
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
|
return
|
||||||
}
|
}
|
||||||
origHandler.ServeHTTP(w, r)
|
origHandler.ServeHTTP(w, r)
|
||||||
|
|
|
@ -157,11 +157,11 @@ func echoReadAllWritePreparedMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path != "/" {
|
||||||
http.Error(w, "Not found.", 404)
|
http.Error(w, "Not found.", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
|
@ -15,11 +15,11 @@ var addr = flag.String("addr", ":8080", "http service address")
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(r.URL)
|
log.Println(r.URL)
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path != "/" {
|
||||||
http.Error(w, "Not found", 404)
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.ServeFile(w, r, "home.html")
|
http.ServeFile(w, r, "home.html")
|
||||||
|
|
|
@ -167,11 +167,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path != "/" {
|
||||||
http.Error(w, "Not found", 404)
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.ServeFile(w, r, "home.html")
|
http.ServeFile(w, r, "home.html")
|
||||||
|
|
|
@ -130,11 +130,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path != "/" {
|
||||||
http.Error(w, "Not found", 404)
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
|
@ -243,7 +243,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
|
||||||
// of the same origin policy check is:
|
// of the same origin policy check is:
|
||||||
//
|
//
|
||||||
// if req.Header.Get("Origin") != "http://"+req.Host {
|
// if req.Header.Get("Origin") != "http://"+req.Host {
|
||||||
// http.Error(w, "Origin not allowed", 403)
|
// http.Error(w, "Origin not allowed", http.StatusForbidden)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue