From a12f6c239cf23007b14eac5cc35e22cb97dc8b37 Mon Sep 17 00:00:00 2001
From: Ibrahim Jarif <ibrahim@dgraph.io>
Date: Thu, 17 Sep 2020 18:42:17 +0530
Subject: [PATCH] chore(query): Return content length header for queries
 (#6469)

This PR adds `Content-Length` header to the response of queries sent via HTTP.

Fixes DGRAPH-1675

(cherry picked from commit ed63786522c9539059d2131750327fa1bfcfee6c)
---
 x/x.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/x/x.go b/x/x.go
index d8d0ab28450..69790da9a22 100644
--- a/x/x.go
+++ b/x/x.go
@@ -441,7 +441,12 @@ func WriteResponse(w http.ResponseWriter, r *http.Request, b []byte) (int, error
 		out = gzw
 	}
 
-	return out.Write(b)
+	bytesWritten, err := out.Write(b)
+	if err != nil {
+		return 0, err
+	}
+	w.Header().Set("Content-Length", strconv.FormatInt(int64(bytesWritten), 10))
+	return bytesWritten, nil
 }
 
 // Min returns the minimum of the two given numbers.