mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-22 05:53:20 +00:00
Add BodyParser v1.6.0
This commit is contained in:
parent
cd7338dbe0
commit
5acffdb2a1
@ -30,7 +30,7 @@ import (
|
||||
|
||||
const (
|
||||
// Version : Fiber release
|
||||
Version = "1.5.0"
|
||||
Version = "1.6.0"
|
||||
// Website : Fiber documentation
|
||||
Website = "https://fiber.wiki"
|
||||
banner = "\x1b[1;32m" + ` ______ __ ______ ______ ______
|
||||
|
10
response.go
10
response.go
@ -181,7 +181,7 @@ func (ctx *Ctx) Json(v interface{}) error {
|
||||
|
||||
// JSON : https://fiber.wiki/context#json
|
||||
func (ctx *Ctx) JSON(v interface{}) error {
|
||||
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
|
||||
ctx.Fasthttp.Response.Header.SetContentType(mimeApplicationJSON)
|
||||
raw, err := jsoniter.Marshal(&v)
|
||||
if err != nil {
|
||||
ctx.Fasthttp.Response.SetBodyString("")
|
||||
@ -200,7 +200,7 @@ func (ctx *Ctx) JsonBytes(raw []byte) {
|
||||
|
||||
// JSONBytes : https://fiber.wiki/context#jsonbytes
|
||||
func (ctx *Ctx) JSONBytes(raw []byte) {
|
||||
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
|
||||
ctx.Fasthttp.Response.Header.SetContentType(mimeApplicationJSON)
|
||||
ctx.Fasthttp.Response.SetBodyString(getString(raw))
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ func (ctx *Ctx) JSONP(v interface{}, cb ...string) error {
|
||||
str += getString(raw) + ");"
|
||||
|
||||
ctx.Set(fasthttp.HeaderXContentTypeOptions, "nosniff")
|
||||
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJs)
|
||||
ctx.Fasthttp.Response.Header.SetContentType(mimeApplicationJavascript)
|
||||
ctx.Fasthttp.Response.SetBodyString(str)
|
||||
|
||||
return nil
|
||||
@ -238,7 +238,7 @@ func (ctx *Ctx) JsonString(raw string) {
|
||||
|
||||
// JSONString : https://fiber.wiki/context#json
|
||||
func (ctx *Ctx) JSONString(raw string) {
|
||||
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
|
||||
ctx.Fasthttp.Response.Header.SetContentType(mimeApplicationJSON)
|
||||
ctx.Fasthttp.Response.SetBodyString(raw)
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ func (ctx *Ctx) XML(v interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.Fasthttp.Response.Header.SetContentType(contentTypeXML)
|
||||
ctx.Fasthttp.Response.Header.SetContentType(mimeApplicationXML)
|
||||
ctx.Fasthttp.Response.SetBody(raw)
|
||||
|
||||
return nil
|
||||
|
30
utils.go
30
utils.go
@ -87,9 +87,9 @@ func getType(ext string) (mime string) {
|
||||
if ext[0] == '.' {
|
||||
ext = ext[1:]
|
||||
}
|
||||
mime = contentTypes[ext]
|
||||
mime = mimeTypes[ext]
|
||||
if mime == "" {
|
||||
return contentTypeOctetStream
|
||||
return mimeApplicationOctetStream
|
||||
}
|
||||
return mime
|
||||
}
|
||||
@ -213,27 +213,17 @@ var statusMessages = map[int]string{
|
||||
}
|
||||
|
||||
const (
|
||||
contentTypeJSON = "application/json"
|
||||
contentTypeJs = "application/javascript"
|
||||
contentTypeXML = "application/xml"
|
||||
contentTypeOctetStream = "application/octet-stream"
|
||||
contentTypeFormURLEncoded = "application/x-www-form-urlencoded"
|
||||
contentTypeMultipartFormData = "multipart/form-data"
|
||||
)
|
||||
|
||||
const (
|
||||
mimeApplicationJSON = "application/json"
|
||||
mimeApplicationJavascrippt = "application/javascript"
|
||||
mimeApplicationXML = "application/xml"
|
||||
mimeTextXML = "text/xml"
|
||||
mimeApplicationOctetStream = "application/octet-stream"
|
||||
mimeApplicationFormURLEncoded = "application/x-www-form-urlencoded"
|
||||
mimeApplicationForm = "application/x-www-form-urlencoded"
|
||||
mimeMultipartForm = "multipart/form-data"
|
||||
mimeApplicationJSON = "application/json"
|
||||
mimeApplicationJavascript = "application/javascript"
|
||||
mimeApplicationXML = "application/xml"
|
||||
mimeTextXML = "text/xml"
|
||||
mimeApplicationOctetStream = "application/octet-stream"
|
||||
mimeApplicationForm = "application/x-www-form-urlencoded"
|
||||
mimeMultipartForm = "multipart/form-data"
|
||||
)
|
||||
|
||||
// https://github.com/nginx/nginx/blob/master/conf/mime.types
|
||||
var contentTypes = map[string]string{
|
||||
var mimeTypes = map[string]string{
|
||||
"html": "text/html",
|
||||
"htm": "text/html",
|
||||
"shtml": "text/html",
|
||||
|
Loading…
x
Reference in New Issue
Block a user