refactor: move json related header vars to internal (#1840)

* refactor: move json related header vars to internal

* refactor: use header.ContentType
This commit is contained in:
Kevin Wan
2022-04-28 15:12:04 +08:00
committed by GitHub
parent cef83efd4e
commit 3bbc90ec24
14 changed files with 58 additions and 42 deletions

View File

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/rest/internal/header"
)
func TestParse(t *testing.T) {
@@ -16,7 +17,7 @@ func TestParse(t *testing.T) {
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("foo", "bar")
w.Header().Set(contentType, applicationJson)
w.Header().Set(header.ContentType, header.JsonContentType)
w.Write([]byte(`{"name":"kevin","value":100}`))
}))
defer svr.Close()
@@ -36,7 +37,7 @@ func TestParseHeaderError(t *testing.T) {
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("foo", "bar")
w.Header().Set(contentType, applicationJson)
w.Header().Set(header.ContentType, header.JsonContentType)
}))
defer svr.Close()
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
@@ -52,7 +53,7 @@ func TestParseNoBody(t *testing.T) {
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("foo", "bar")
w.Header().Set(contentType, applicationJson)
w.Header().Set(header.ContentType, header.JsonContentType)
}))
defer svr.Close()
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)