From 0df6719e7b9ca39083409d640c84d035900cabe8 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Sun, 25 Jun 2017 22:09:57 -0700
Subject: [PATCH] Make sure request data is a JSON string instead of a []byte

---
 httpbin/handlers_test.go | 4 +++-
 httpbin/helpers.go       | 2 +-
 httpbin/httpbin.go       | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index e90b4ae..60868f7 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -502,7 +502,9 @@ func TestPost__JSON(t *testing.T) {
 		t.Fatalf("failed to unmarshal body %s from JSON: %s", w.Body, err)
 	}
 
-	assertBytesEqual(t, resp.Data, inputBody)
+	if resp.Data != string(inputBody) {
+		t.Fatalf("expected data == %#v, got %#v", string(inputBody), resp.Data)
+	}
 	if len(resp.Args) > 0 {
 		t.Fatalf("expected no query params, got %#v", resp.Args)
 	}
diff --git a/httpbin/helpers.go b/httpbin/helpers.go
index e769e11..6a5341f 100644
--- a/httpbin/helpers.go
+++ b/httpbin/helpers.go
@@ -87,7 +87,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
 		r.Body.Close()
 		return err
 	}
-	resp.Data = body
+	resp.Data = string(body)
 
 	// After reading the body to populate resp.Data, we need to re-wrap it in
 	// an io.Reader for further processing below
diff --git a/httpbin/httpbin.go b/httpbin/httpbin.go
index 2996249..c33f1e5 100644
--- a/httpbin/httpbin.go
+++ b/httpbin/httpbin.go
@@ -41,7 +41,7 @@ type bodyResponse struct {
 	Origin  string      `json:"origin"`
 	URL     string      `json:"url"`
 
-	Data  []byte              `json:"data"`
+	Data  string              `json:"data"`
 	Files map[string][]string `json:"files"`
 	Form  map[string][]string `json:"form"`
 	JSON  interface{}         `json:"json"`
-- 
GitLab