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

Function WriteResponse

x/x.go:593–609  ·  view source on GitHub ↗

WriteResponse writes response body, transparently compressing if necessary.

(w http.ResponseWriter, r *http.Request, b []byte)

Source from the content-addressed store, hash-verified

591
592// WriteResponse writes response body, transparently compressing if necessary.
593func WriteResponse(w http.ResponseWriter, r *http.Request, b []byte) (int, error) {
594 var out io.Writer = w
595
596 if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
597 w.Header().Set("Content-Encoding", "gzip")
598 gzw := builtinGzip.NewWriter(w)
599 defer gzw.Close()
600 out = gzw
601 }
602
603 bytesWritten, err := out.Write(b)
604 if err != nil {
605 return 0, err
606 }
607 w.Header().Set("Content-Length", strconv.FormatInt(int64(bytesWritten), 10))
608 return bytesWritten, nil
609}
610
611// Min returns the minimum of the two given numbers.
612func Min(a, b uint64) uint64 {

Callers 5

loginHandlerFunction · 0.92
queryHandlerFunction · 0.92
mutationHandlerFunction · 0.92
commitHandlerFunction · 0.92
writeSuccessResponseFunction · 0.92

Calls 4

WriteMethod · 0.95
GetMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected