Modify http Method String Literal to Variable (#728)

This commit is contained in:
Rn 2021-12-20 01:21:45 +09:00 committed by GitHub
parent 1905f7e442
commit 2c89656910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 12 deletions

View File

@ -178,7 +178,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
} }
req := &http.Request{ req := &http.Request{
Method: "GET", Method: http.MethodGet,
URL: u, URL: u,
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,

View File

@ -163,7 +163,7 @@ func TestProxyDial(t *testing.T) {
// Capture the request Host header. // Capture the request Host header.
s.Server.Config.Handler = http.HandlerFunc( s.Server.Config.Handler = http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
if r.Method == "CONNECT" { if r.Method == http.MethodConnect {
connect = true connect = true
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
return return
@ -203,7 +203,7 @@ func TestProxyAuthorizationDial(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
proxyAuth := r.Header.Get("Proxy-Authorization") proxyAuth := r.Header.Get("Proxy-Authorization")
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 == http.MethodConnect && proxyAuth == expectedProxyAuth {
connect = true connect = true
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
return return
@ -463,7 +463,7 @@ func TestBadMethod(t *testing.T) {
})) }))
defer s.Close() 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 { if err != nil {
t.Fatalf("NewRequest returned error %v", err) t.Fatalf("NewRequest returned error %v", err)
} }
@ -735,7 +735,7 @@ func TestHost(t *testing.T) {
Dial: dialer.NetDial, Dial: dialer.NetDial,
TLSClientConfig: dialer.TLSClientConfig, 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 != "" { if tt.header != "" {
req.Host = tt.header req.Host = tt.header
} }

View File

@ -160,7 +160,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found.", http.StatusNotFound) http.Error(w, "Not found.", http.StatusNotFound)
return return
} }
if r.Method != "GET" { if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return return
} }

View File

@ -18,7 +18,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound) http.Error(w, "Not found", http.StatusNotFound)
return return
} }
if r.Method != "GET" { if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return return
} }

View File

@ -170,7 +170,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound) http.Error(w, "Not found", http.StatusNotFound)
return return
} }
if r.Method != "GET" { if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return return
} }

View File

@ -133,7 +133,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not found", http.StatusNotFound) http.Error(w, "Not found", http.StatusNotFound)
return return
} }
if r.Method != "GET" { if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return return
} }

View File

@ -48,7 +48,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
} }
connectReq := &http.Request{ connectReq := &http.Request{
Method: "CONNECT", Method: http.MethodConnect,
URL: &url.URL{Opaque: addr}, URL: &url.URL{Opaque: addr},
Host: addr, Host: addr,
Header: connectHeader, Header: connectHeader,

View File

@ -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") 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") return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET")
} }

View File

@ -98,7 +98,7 @@ func TestBufioReuse(t *testing.T) {
} }
upgrader := Upgrader{} upgrader := Upgrader{}
c, err := upgrader.Upgrade(resp, &http.Request{ c, err := upgrader.Upgrade(resp, &http.Request{
Method: "GET", Method: http.MethodGet,
Header: http.Header{ Header: http.Header{
"Upgrade": []string{"websocket"}, "Upgrade": []string{"websocket"},
"Connection": []string{"upgrade"}, "Connection": []string{"upgrade"},