MCPcopy
hub / github.com/dgraph-io/dgraph / readRequest

Function readRequest

dgraph/cmd/alpha/http.go:62–87  ·  view source on GitHub ↗

Read request body, transparently decompressing if necessary. Return nil on error.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

60
61// Read request body, transparently decompressing if necessary. Return nil on error.
62func readRequest(w http.ResponseWriter, r *http.Request) []byte {
63 var in io.Reader = r.Body
64
65 if enc := r.Header.Get("Content-Encoding"); enc != "" && enc != "identity" {
66 if enc == "gzip" {
67 gz, err := gzip.NewReader(r.Body)
68 if err != nil {
69 x.SetStatus(w, x.Error, "Unable to create decompressor")
70 return nil
71 }
72 defer gz.Close()
73 in = gz
74 } else {
75 x.SetStatus(w, x.ErrorInvalidRequest, "Unsupported content encoding")
76 return nil
77 }
78 }
79
80 body, err := io.ReadAll(in)
81 if err != nil {
82 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
83 return nil
84 }
85
86 return body
87}
88
89// parseUint64 reads the value for given URL parameter from request and
90// parses it into uint64, empty string is converted into zero value

Callers 7

loginHandlerFunction · 0.85
queryHandlerFunction · 0.85
mutationHandlerFunction · 0.85
commitHandlerFunction · 0.85
alterHandlerFunction · 0.85
adminSchemaHandlerFunction · 0.85
schemaValidateHandlerFunction · 0.85

Calls 4

SetStatusFunction · 0.92
GetMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected