@@ -146,13 +146,17 @@ func NewHTTPServer(cors []string, srv *Server) *http.Server {
146
146
147
147
// ServeHTTP serves JSON-RPC requests over HTTP.
148
148
func (srv * Server ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
149
+ // Permit dumb empty requests for remote health-checks (AWS)
150
+ if r .Method == "GET" && r .ContentLength == 0 && r .URL .RawQuery == "" {
151
+ return
152
+ }
153
+ // For meaningful requests, validate it's size and content type
149
154
if r .ContentLength > maxHTTPRequestContentLength {
150
155
http .Error (w ,
151
156
fmt .Sprintf ("content length too large (%d>%d)" , r .ContentLength , maxHTTPRequestContentLength ),
152
157
http .StatusRequestEntityTooLarge )
153
158
return
154
159
}
155
-
156
160
ct := r .Header .Get ("content-type" )
157
161
mt , _ , err := mime .ParseMediaType (ct )
158
162
if err != nil || mt != "application/json" {
@@ -161,14 +165,13 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
161
165
http .StatusUnsupportedMediaType )
162
166
return
163
167
}
164
-
165
- w .Header ().Set ("content-type" , "application/json" )
166
-
167
- // create a codec that reads direct from the request body until
168
- // EOF and writes the response to w and order the server to process
169
- // a single request.
168
+ // All checks passed, create a codec that reads direct from the request body
169
+ // untilEOF and writes the response to w and order the server to process a
170
+ // single request.
170
171
codec := NewJSONCodec (& httpReadWriteNopCloser {r .Body , w })
171
172
defer codec .Close ()
173
+
174
+ w .Header ().Set ("content-type" , "application/json" )
172
175
srv .ServeSingleRequest (codec , OptionMethodInvocation )
173
176
}
174
177
0 commit comments