Skip to content

Commit 0647012

Browse files
KimMachineGungaryburd
authored andcommitted
Modify http status code to variable
1 parent f37d158 commit 0647012

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

client_server_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ func newTLSServer(t *testing.T) *cstServer {
7272
func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7373
if r.URL.Path != cstPath {
7474
t.Logf("path=%v, want %v", r.URL.Path, cstPath)
75-
http.Error(w, "bad path", 400)
75+
http.Error(w, "bad path", http.StatusBadRequest)
7676
return
7777
}
7878
if r.URL.RawQuery != cstRawQuery {
7979
t.Logf("query=%v, want %v", r.URL.RawQuery, cstRawQuery)
80-
http.Error(w, "bad path", 400)
80+
http.Error(w, "bad path", http.StatusBadRequest)
8181
return
8282
}
8383
subprotos := Subprotocols(r)
8484
if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) {
8585
t.Logf("subprotols=%v, want %v", subprotos, cstDialer.Subprotocols)
86-
http.Error(w, "bad protocol", 400)
86+
http.Error(w, "bad protocol", http.StatusBadRequest)
8787
return
8888
}
8989
ws, err := cstUpgrader.Upgrade(w, r, http.Header{"Set-Cookie": {"sessionID=1234"}})
@@ -160,13 +160,13 @@ func TestProxyDial(t *testing.T) {
160160
func(w http.ResponseWriter, r *http.Request) {
161161
if r.Method == "CONNECT" {
162162
connect = true
163-
w.WriteHeader(200)
163+
w.WriteHeader(http.StatusOK)
164164
return
165165
}
166166

167167
if !connect {
168168
t.Log("connect not received")
169-
http.Error(w, "connect not received", 405)
169+
http.Error(w, "connect not received", http.StatusMethodNotAllowed)
170170
return
171171
}
172172
origHandler.ServeHTTP(w, r)
@@ -200,13 +200,13 @@ func TestProxyAuthorizationDial(t *testing.T) {
200200
expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
201201
if r.Method == "CONNECT" && proxyAuth == expectedProxyAuth {
202202
connect = true
203-
w.WriteHeader(200)
203+
w.WriteHeader(http.StatusOK)
204204
return
205205
}
206206

207207
if !connect {
208208
t.Log("connect with proxy authorization not received")
209-
http.Error(w, "connect with proxy authorization not received", 405)
209+
http.Error(w, "connect with proxy authorization not received", http.StatusMethodNotAllowed)
210210
return
211211
}
212212
origHandler.ServeHTTP(w, r)

examples/autobahn/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ func echoReadAllWritePreparedMessage(w http.ResponseWriter, r *http.Request) {
157157

158158
func serveHome(w http.ResponseWriter, r *http.Request) {
159159
if r.URL.Path != "/" {
160-
http.Error(w, "Not found.", 404)
160+
http.Error(w, "Not found.", http.StatusNotFound)
161161
return
162162
}
163163
if r.Method != "GET" {
164-
http.Error(w, "Method not allowed", 405)
164+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
165165
return
166166
}
167167
w.Header().Set("Content-Type", "text/html; charset=utf-8")

examples/chat/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var addr = flag.String("addr", ":8080", "http service address")
1515
func serveHome(w http.ResponseWriter, r *http.Request) {
1616
log.Println(r.URL)
1717
if r.URL.Path != "/" {
18-
http.Error(w, "Not found", 404)
18+
http.Error(w, "Not found", http.StatusNotFound)
1919
return
2020
}
2121
if r.Method != "GET" {
22-
http.Error(w, "Method not allowed", 405)
22+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
2323
return
2424
}
2525
http.ServeFile(w, r, "home.html")

examples/command/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
167167

168168
func serveHome(w http.ResponseWriter, r *http.Request) {
169169
if r.URL.Path != "/" {
170-
http.Error(w, "Not found", 404)
170+
http.Error(w, "Not found", http.StatusNotFound)
171171
return
172172
}
173173
if r.Method != "GET" {
174-
http.Error(w, "Method not allowed", 405)
174+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
175175
return
176176
}
177177
http.ServeFile(w, r, "home.html")

examples/filewatch/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
130130

131131
func serveHome(w http.ResponseWriter, r *http.Request) {
132132
if r.URL.Path != "/" {
133-
http.Error(w, "Not found", 404)
133+
http.Error(w, "Not found", http.StatusNotFound)
134134
return
135135
}
136136
if r.Method != "GET" {
137-
http.Error(w, "Method not allowed", 405)
137+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
138138
return
139139
}
140140
w.Header().Set("Content-Type", "text/html; charset=utf-8")

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
243243
// of the same origin policy check is:
244244
//
245245
// if req.Header.Get("Origin") != "http://"+req.Host {
246-
// http.Error(w, "Origin not allowed", 403)
246+
// http.Error(w, "Origin not allowed", http.StatusForbidden)
247247
// return
248248
// }
249249
//

0 commit comments

Comments
 (0)