Skip to content

Commit

Permalink
Modify http Method String Literal to Variable (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
thak1411 committed Dec 19, 2021
1 parent 1905f7e commit 2c89656
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -178,7 +178,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
}

req := &http.Request{
Method: "GET",
Method: http.MethodGet,
URL: u,
Proto: "HTTP/1.1",
ProtoMajor: 1,
Expand Down
8 changes: 4 additions & 4 deletions client_server_test.go
Expand Up @@ -163,7 +163,7 @@ func TestProxyDial(t *testing.T) {
// Capture the request Host header.
s.Server.Config.Handler = http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.Method == "CONNECT" {
if r.Method == http.MethodConnect {
connect = true
w.WriteHeader(http.StatusOK)
return
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestProxyAuthorizationDial(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
proxyAuth := r.Header.Get("Proxy-Authorization")
expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
if r.Method == "CONNECT" && proxyAuth == expectedProxyAuth {
if r.Method == http.MethodConnect && proxyAuth == expectedProxyAuth {
connect = true
w.WriteHeader(http.StatusOK)
return
Expand Down Expand Up @@ -463,7 +463,7 @@ func TestBadMethod(t *testing.T) {
}))
defer s.Close()

req, err := http.NewRequest("POST", s.URL, strings.NewReader(""))
req, err := http.NewRequest(http.MethodPost, s.URL, strings.NewReader(""))
if err != nil {
t.Fatalf("NewRequest returned error %v", err)
}
Expand Down Expand Up @@ -735,7 +735,7 @@ func TestHost(t *testing.T) {
Dial: dialer.NetDial,
TLSClientConfig: dialer.TLSClientConfig,
}
req, _ := http.NewRequest("GET", httpProtos[tt.server]+tt.url+"/", nil)
req, _ := http.NewRequest(http.MethodGet, httpProtos[tt.server]+tt.url+"/", nil)
if tt.header != "" {
req.Host = tt.header
}
Expand Down
2 changes: 1 addition & 1 deletion examples/autobahn/server.go
Expand Up @@ -160,7 +160,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found.", http.StatusNotFound)
return
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/main.go
Expand Up @@ -18,7 +18,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound)
return
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/command/main.go
Expand Up @@ -170,7 +170,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound)
return
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/filewatch/main.go
Expand Up @@ -133,7 +133,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound)
return
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
Expand Down
2 changes: 1 addition & 1 deletion proxy.go
Expand Up @@ -48,7 +48,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
}

connectReq := &http.Request{
Method: "CONNECT",
Method: http.MethodConnect,
URL: &url.URL{Opaque: addr},
Host: addr,
Header: connectHeader,
Expand Down
2 changes: 1 addition & 1 deletion server.go
Expand Up @@ -133,7 +133,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'websocket' token not found in 'Upgrade' header")
}

if r.Method != "GET" {
if r.Method != http.MethodGet {
return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET")
}

Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Expand Up @@ -98,7 +98,7 @@ func TestBufioReuse(t *testing.T) {
}
upgrader := Upgrader{}
c, err := upgrader.Upgrade(resp, &http.Request{
Method: "GET",
Method: http.MethodGet,
Header: http.Header{
"Upgrade": []string{"websocket"},
"Connection": []string{"upgrade"},
Expand Down

0 comments on commit 2c89656

Please sign in to comment.