Skip to content

Commit 3238fe8

Browse files
committed
chore(golang)!: don't set "charset=utf8" parameter for "Content-Type"
RFC 4627 does not define a charset parameter because it requires that JSON is always encoded as Unicode (c) request/request#383 (comment)
1 parent 1ece6c0 commit 3238fe8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/go/chi/mysql/routes.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
4343
case sql.ErrNoRows:
4444
w.WriteHeader(http.StatusNotFound)
4545
case nil:
46-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
46+
w.Header().Set("Content-Type", "application/json")
4747
json.NewEncoder(w).Encode(&result)
4848
default:
4949
fmt.Fprintf(os.Stderr, "Get failed: %v\n", err)
@@ -68,7 +68,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
6868
case sql.ErrNoRows:
6969
w.WriteHeader(http.StatusNotFound)
7070
case nil:
71-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
71+
w.Header().Set("Content-Type", "application/json")
7272
json.NewEncoder(w).Encode(&result)
7373
default:
7474
fmt.Fprintf(os.Stderr, "Get failed: %v\n", err)
@@ -93,7 +93,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
9393
case sql.ErrNoRows:
9494
w.WriteHeader(http.StatusNotFound)
9595
case nil:
96-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
96+
w.Header().Set("Content-Type", "application/json")
9797
json.NewEncoder(w).Encode(&result)
9898
default:
9999
fmt.Fprintf(os.Stderr, "Select failed: %v\n", err)
@@ -141,7 +141,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
141141
case sql.ErrNoRows:
142142
w.WriteHeader(http.StatusNotFound)
143143
case nil:
144-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
144+
w.Header().Set("Content-Type", "application/json")
145145
json.NewEncoder(w).Encode(&result)
146146
default:
147147
fmt.Fprintf(os.Stderr, "Get failed: %v\n", err)
@@ -193,7 +193,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
193193
}
194194

195195
func internalServerError(w http.ResponseWriter) {
196-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
196+
w.Header().Set("Content-Type", "application/json")
197197
w.WriteHeader(http.StatusInternalServerError)
198198
io.WriteString(w, `{"error":"Internal Server Error"}`)
199199
}

src/templates/routes.go.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ endpoints.forEach(function(endpoint) {
207207
case sql.ErrNoRows:
208208
w.WriteHeader(http.StatusNotFound)
209209
case nil:
210-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
210+
w.Header().Set("Content-Type", "application/json")
211211
json.NewEncoder(w).Encode(&result)
212212
default:
213213
fmt.Fprintf(os.Stderr, "<%- queryFunction %> failed: %v\n", err)
@@ -298,7 +298,7 @@ endpoints.forEach(function(endpoint) {
298298
<%# IMPORTANT: WriteHeader() must be called after w.Header() -%>
299299
<%# w.Write() vs io.WriteString(): https://stackoverflow.com/questions/37863374/whats-the-difference-between-responsewriter-write-and-io-writestring -%>
300300
func internalServerError(w http.ResponseWriter) {
301-
w.Header().Set("Content-Type", "application/json; charset=utf-8")
301+
w.Header().Set("Content-Type", "application/json")
302302
w.WriteHeader(http.StatusInternalServerError)
303303
io.WriteString(w, `{"error":"Internal Server Error"}`)
304304
}

0 commit comments

Comments
 (0)