Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions rpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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)
}

Expand Down