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