MCPcopy Create free account
hub / github.com/CPChain/chain / validateRequest

Function validateRequest

api/rpc/http.go:204–218  ·  view source on GitHub ↗

validateRequest returns a non-zero response code and error message if the request is invalid.

(r *http.Request)

Source from the content-addressed store, hash-verified

202// validateRequest returns a non-zero response code and error message if the
203// request is invalid.
204func validateRequest(r *http.Request) (int, error) {
205 if r.Method == http.MethodPut || r.Method == http.MethodDelete {
206 return http.StatusMethodNotAllowed, errors.New("method not allowed")
207 }
208 if r.ContentLength > maxRequestContentLength {
209 err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxRequestContentLength)
210 return http.StatusRequestEntityTooLarge, err
211 }
212 mt, _, err := mime.ParseMediaType(r.Header.Get("content-type"))
213 if r.Method != http.MethodOptions && (err != nil || mt != contentType) {
214 err := fmt.Errorf("invalid content type, only %s is supported", contentType)
215 return http.StatusUnsupportedMediaType, err
216 }
217 return 0, nil
218}
219
220func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler {
221 // disable CORS support if user has not specified a custom CORS configuration

Callers 2

ServeHTTPMethod · 0.85
testHTTPErrorResponseFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by 1

testHTTPErrorResponseFunction · 0.68