aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-11-16 23:03:06 +0800
committerGitHub <noreply@github.com>2017-11-16 23:03:06 +0800
commit87f5b4123c6e2a48ad67426a34763acc50c821f8 (patch)
treec7ae53d07f3635a46533162c2242afdc273eecc1
parent5aa3eac22d80c754d70651a918bccc9b3d1d216f (diff)
parent4013e23312257d79caf4fb5030881d30a62cb618 (diff)
downloadgo-tangerine-87f5b4123c6e2a48ad67426a34763acc50c821f8.tar.gz
go-tangerine-87f5b4123c6e2a48ad67426a34763acc50c821f8.tar.zst
go-tangerine-87f5b4123c6e2a48ad67426a34763acc50c821f8.zip
Merge pull request #15496 from karalabe/rpc-get-healthcheck
rpc: allow dumb empty requests for AWS health checks
-rw-r--r--rpc/http.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/rpc/http.go b/rpc/http.go
index 3f572b34c..2ac9f6c37 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -146,13 +146,17 @@ 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 == "" {
+ return
+ }
+ // For meaningful requests, validate it's size and content type
if r.ContentLength > maxHTTPRequestContentLength {
http.Error(w,
fmt.Sprintf("content length too large (%d>%d)", r.ContentLength, maxHTTPRequestContentLength),
http.StatusRequestEntityTooLarge)
return
}
-
ct := r.Header.Get("content-type")
mt, _, err := mime.ParseMediaType(ct)
if err != nil || mt != "application/json" {
@@ -161,14 +165,13 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.StatusUnsupportedMediaType)
return
}
-
- w.Header().Set("content-type", "application/json")
-
- // create a codec that reads direct from the request body until
- // EOF and writes the response to w and order the server to process
- // a single request.
+ // All checks passed, create a codec that reads direct from the request body
+ // untilEOF and writes the response to w and order the server to process a
+ // single request.
codec := NewJSONCodec(&httpReadWriteNopCloser{r.Body, w})
defer codec.Close()
+
+ w.Header().Set("content-type", "application/json")
srv.ServeSingleRequest(codec, OptionMethodInvocation)
}