mirror of https://github.com/gofiber/fiber.git
Switch to text/javascript as per RFC9239 (#2146)
* Switch to text/javascript as per RFC9239 * Add deprecated flag to application/javascriptpull/2150/head
parent
925d5d03dc
commit
9a6002056c
2
ctx.go
2
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
24
helpers.go
24
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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue