diff options
author | Janos Guljas <janos@resenje.org> | 2017-12-14 17:35:49 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2017-12-14 17:36:12 +0800 |
commit | 47a801455966298d1d1519eebb955024c8f02b84 (patch) | |
tree | 5b8144ba4844092dc0bae599fc3314eaacf1a7b4 /rpc | |
parent | 19982f946735948478b6b7e7706f1b615f171d0d (diff) | |
parent | 3654aeaa4f87452ac5bc801a18808189595e2ef8 (diff) | |
download | dexon-47a801455966298d1d1519eebb955024c8f02b84.tar dexon-47a801455966298d1d1519eebb955024c8f02b84.tar.gz dexon-47a801455966298d1d1519eebb955024c8f02b84.tar.bz2 dexon-47a801455966298d1d1519eebb955024c8f02b84.tar.lz dexon-47a801455966298d1d1519eebb955024c8f02b84.tar.xz dexon-47a801455966298d1d1519eebb955024c8f02b84.tar.zst dexon-47a801455966298d1d1519eebb955024c8f02b84.zip |
cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Fix a conflict in cmd/swarm envVarsOverride function.
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/http.go | 8 | ||||
-rw-r--r-- | rpc/http_test.go | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/rpc/http.go b/rpc/http.go index 5941c0677..a26559b12 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -67,7 +67,7 @@ func (hc *httpConn) Close() error { // DialHTTP creates a new RPC clients that connection to an RPC server over HTTP. func DialHTTP(endpoint string) (*Client, error) { - req, err := http.NewRequest("POST", endpoint, nil) + req, err := http.NewRequest(http.MethodPost, endpoint, nil) if err != nil { return nil, err } @@ -149,7 +149,7 @@ func NewHTTPServer(cors []string, srv *Server) *http.Server { // ServeHTTP serves JSON-RPC requests over HTTP. func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Permit dumb empty requests for remote health-checks (AWS) - if r.Method == "GET" && r.ContentLength == 0 && r.URL.RawQuery == "" { + if r.Method == http.MethodGet && r.ContentLength == 0 && r.URL.RawQuery == "" { return } if code, err := validateRequest(r); err != nil { @@ -169,7 +169,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // validateRequest returns a non-zero response code and error message if the // request is invalid. func validateRequest(r *http.Request) (int, error) { - if r.Method == "PUT" || r.Method == "DELETE" { + if r.Method == http.MethodPut || r.Method == http.MethodDelete { return http.StatusMethodNotAllowed, errors.New("method not allowed") } if r.ContentLength > maxHTTPRequestContentLength { @@ -192,7 +192,7 @@ func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler { c := cors.New(cors.Options{ AllowedOrigins: allowedOrigins, - AllowedMethods: []string{"POST", "GET"}, + AllowedMethods: []string{http.MethodPost, http.MethodGet}, MaxAge: 600, AllowedHeaders: []string{"*"}, }) diff --git a/rpc/http_test.go b/rpc/http_test.go index 1cb7a7acb..aed84f683 100644 --- a/rpc/http_test.go +++ b/rpc/http_test.go @@ -24,25 +24,25 @@ import ( ) func TestHTTPErrorResponseWithDelete(t *testing.T) { - testHTTPErrorResponse(t, "DELETE", contentType, "", http.StatusMethodNotAllowed) + testHTTPErrorResponse(t, http.MethodDelete, contentType, "", http.StatusMethodNotAllowed) } func TestHTTPErrorResponseWithPut(t *testing.T) { - testHTTPErrorResponse(t, "PUT", contentType, "", http.StatusMethodNotAllowed) + testHTTPErrorResponse(t, http.MethodPut, contentType, "", http.StatusMethodNotAllowed) } func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) { - body := make([]rune, maxHTTPRequestContentLength+1, maxHTTPRequestContentLength+1) + body := make([]rune, maxHTTPRequestContentLength+1) testHTTPErrorResponse(t, - "POST", contentType, string(body), http.StatusRequestEntityTooLarge) + http.MethodPost, contentType, string(body), http.StatusRequestEntityTooLarge) } func TestHTTPErrorResponseWithEmptyContentType(t *testing.T) { - testHTTPErrorResponse(t, "POST", "", "", http.StatusUnsupportedMediaType) + testHTTPErrorResponse(t, http.MethodPost, "", "", http.StatusUnsupportedMediaType) } func TestHTTPErrorResponseWithValidRequest(t *testing.T) { - testHTTPErrorResponse(t, "POST", contentType, "", 0) + testHTTPErrorResponse(t, http.MethodPost, contentType, "", 0) } func testHTTPErrorResponse(t *testing.T, method, contentType, body string, expected int) { |