Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify http Method String Literal to Variable #728

Merged
merged 1 commit into from Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -176,7 +176,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 @@ -131,7 +131,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