diff --git a/ctx.go b/ctx.go index b5bc5f01..ac5b9293 100644 --- a/ctx.go +++ b/ctx.go @@ -813,7 +813,7 @@ func (c *Ctx) JSONP(data interface{}, callback ...string) error { result = cb + "(" + c.app.getString(raw) + ");" c.setCanonical(HeaderXContentTypeOptions, "nosniff") - c.fasthttp.Response.Header.SetContentType(MIMEApplicationJavaScriptCharsetUTF8) + c.fasthttp.Response.Header.SetContentType(MIMETextJavaScriptCharsetUTF8) return c.SendString(result) } diff --git a/ctx_test.go b/ctx_test.go index f1bcebfd..925fbd1b 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -2399,7 +2399,7 @@ func Test_Ctx_JSONP(t *testing.T) { }) utils.AssertEqual(t, nil, err) utils.AssertEqual(t, `callback({"Age":20,"Name":"Grame"});`, string(c.Response().Body())) - utils.AssertEqual(t, "application/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type"))) + utils.AssertEqual(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type"))) err = c.JSONP(Map{ "Name": "Grame", @@ -2407,7 +2407,7 @@ func Test_Ctx_JSONP(t *testing.T) { }, "john") utils.AssertEqual(t, nil, err) utils.AssertEqual(t, `john({"Age":20,"Name":"Grame"});`, string(c.Response().Body())) - utils.AssertEqual(t, "application/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type"))) + utils.AssertEqual(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type"))) } // go test -v -run=^$ -bench=Benchmark_Ctx_JSONP -benchmem -count=4 diff --git a/helpers.go b/helpers.go index c3360ad0..c611b917 100644 --- a/helpers.go +++ b/helpers.go @@ -385,21 +385,25 @@ const ( // MIME types that are commonly used const ( - MIMETextXML = "text/xml" - MIMETextHTML = "text/html" - MIMETextPlain = "text/plain" - MIMEApplicationXML = "application/xml" - MIMEApplicationJSON = "application/json" + MIMETextXML = "text/xml" + MIMETextHTML = "text/html" + MIMETextPlain = "text/plain" + MIMETextJavaScript = "text/javascript" + MIMEApplicationXML = "application/xml" + MIMEApplicationJSON = "application/json" + // Deprecated: use MIMETextJavaScript instead MIMEApplicationJavaScript = "application/javascript" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEOctetStream = "application/octet-stream" MIMEMultipartForm = "multipart/form-data" - MIMETextXMLCharsetUTF8 = "text/xml; charset=utf-8" - MIMETextHTMLCharsetUTF8 = "text/html; charset=utf-8" - MIMETextPlainCharsetUTF8 = "text/plain; charset=utf-8" - MIMEApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" - MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" + MIMETextXMLCharsetUTF8 = "text/xml; charset=utf-8" + MIMETextHTMLCharsetUTF8 = "text/html; charset=utf-8" + MIMETextPlainCharsetUTF8 = "text/plain; charset=utf-8" + MIMETextJavaScriptCharsetUTF8 = "text/javascript; charset=utf-8" + MIMEApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" + MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" + // Deprecated: use MIMETextJavaScriptCharsetUTF8 instead MIMEApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" ) diff --git a/utils/http.go b/utils/http.go index d61560ce..fc524023 100644 --- a/utils/http.go +++ b/utils/http.go @@ -134,6 +134,7 @@ var statusMessage = []string{ // MIME types were copied from https://github.com/nginx/nginx/blob/67d2a9541826ecd5db97d604f23460210fd3e517/conf/mime.types with the following updates: // - Use "application/xml" instead of "text/xml" as recommended per https://datatracker.ietf.org/doc/html/rfc7303#section-4.1 +// - Use "text/javascript" instead of "application/javascript" as recommended per https://www.rfc-editor.org/rfc/rfc9239#name-text-javascript var mimeExtensions = map[string]string{ "html": "text/html", "htm": "text/html", @@ -143,7 +144,7 @@ var mimeExtensions = map[string]string{ "gif": "image/gif", "jpeg": "image/jpeg", "jpg": "image/jpeg", - "js": "application/javascript", + "js": "text/javascript", "atom": "application/atom+xml", "rss": "application/rss+xml", "mml": "text/mathml",