aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/http.go
diff options
context:
space:
mode:
authorVitaly V <vvelikodny@gmail.com>2017-12-13 02:12:32 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-12-13 02:12:32 +0800
commitf258a21a63347a43a80d7834beb39f276a328ba6 (patch)
treebd48f609b050429650b79e596a4caf176bb9bec4 /rpc/http.go
parentfd777bb2104f15cb7c2f7eede7069ad436e29b57 (diff)
downloadgo-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar.gz
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar.bz2
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar.lz
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar.xz
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.tar.zst
go-tangerine-f258a21a63347a43a80d7834beb39f276a328ba6.zip
rpc: use method constants instead of literal strings (#15652)
Diffstat (limited to 'rpc/http.go')
-rw-r--r--rpc/http.go8
1 files changed, 4 insertions, 4 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{"*"},
})