mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-22 23:04:14 +00:00
Add more comments
This commit is contained in:
parent
305c60e5e2
commit
66632ccda9
159
context.go
159
context.go
@ -111,7 +111,9 @@ func releaseConn(conn *Conn) {
|
|||||||
poolConn.Put(conn)
|
poolConn.Put(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accepts : https://fiber.wiki/context#accepts
|
// Checks, if the specified extensions or content types are acceptable.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#accepts
|
||||||
func (ctx *Ctx) Accepts(offers ...string) (offer string) {
|
func (ctx *Ctx) Accepts(offers ...string) (offer string) {
|
||||||
if len(offers) == 0 {
|
if len(offers) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@ -149,7 +151,9 @@ func (ctx *Ctx) Accepts(offers ...string) (offer string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptsCharsets : https://fiber.wiki/context#acceptscharsets
|
// Checks, if the specified charset is acceptable.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#accepts
|
||||||
func (ctx *Ctx) AcceptsCharsets(offers ...string) (offer string) {
|
func (ctx *Ctx) AcceptsCharsets(offers ...string) (offer string) {
|
||||||
if len(offers) == 0 {
|
if len(offers) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@ -175,7 +179,9 @@ func (ctx *Ctx) AcceptsCharsets(offers ...string) (offer string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptsEncodings : https://fiber.wiki/context#acceptsencodings
|
// Checks, if the specified encoding is acceptable.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#accepts
|
||||||
func (ctx *Ctx) AcceptsEncodings(offers ...string) (offer string) {
|
func (ctx *Ctx) AcceptsEncodings(offers ...string) (offer string) {
|
||||||
if len(offers) == 0 {
|
if len(offers) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@ -201,7 +207,9 @@ func (ctx *Ctx) AcceptsEncodings(offers ...string) (offer string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptsLanguages : https://fiber.wiki/context#acceptslanguages
|
// Checks, if the specified language is acceptable.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#accepts
|
||||||
func (ctx *Ctx) AcceptsLanguages(offers ...string) (offer string) {
|
func (ctx *Ctx) AcceptsLanguages(offers ...string) (offer string) {
|
||||||
if len(offers) == 0 {
|
if len(offers) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@ -226,7 +234,10 @@ func (ctx *Ctx) AcceptsLanguages(offers ...string) (offer string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append : https://fiber.wiki/context#append
|
// Appends the specified value to the HTTP response header field.
|
||||||
|
// If the header is not already set, it creates the header with the specified value.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#append
|
||||||
func (ctx *Ctx) Append(field string, values ...string) {
|
func (ctx *Ctx) Append(field string, values ...string) {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return
|
return
|
||||||
@ -242,7 +253,9 @@ func (ctx *Ctx) Append(field string, values ...string) {
|
|||||||
ctx.Set(field, h)
|
ctx.Set(field, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attachment : https://fiber.wiki/context#attachment
|
// Sets the HTTP response Content-Disposition header field to attachment.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#attachment
|
||||||
func (ctx *Ctx) Attachment(name ...string) {
|
func (ctx *Ctx) Attachment(name ...string) {
|
||||||
if len(name) > 0 {
|
if len(name) > 0 {
|
||||||
filename := filepath.Base(name[0])
|
filename := filepath.Base(name[0])
|
||||||
@ -253,12 +266,17 @@ func (ctx *Ctx) Attachment(name ...string) {
|
|||||||
ctx.Set(HeaderContentDisposition, "attachment")
|
ctx.Set(HeaderContentDisposition, "attachment")
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseURL : https://fiber.wiki/context#baseurl
|
// Returns base URL (protocol + host) as a string.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#baseurl
|
||||||
func (ctx *Ctx) BaseURL() string {
|
func (ctx *Ctx) BaseURL() string {
|
||||||
return ctx.Protocol() + "://" + ctx.Hostname()
|
return ctx.Protocol() + "://" + ctx.Hostname()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Body : https://fiber.wiki/context#body
|
// Contains the raw body submitted in a POST request.
|
||||||
|
// If a key is provided, it returns the form value
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#body
|
||||||
func (ctx *Ctx) Body(key ...string) string {
|
func (ctx *Ctx) Body(key ...string) string {
|
||||||
// Return request body
|
// Return request body
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
@ -271,7 +289,11 @@ func (ctx *Ctx) Body(key ...string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// BodyParser : https://fiber.wiki/context#bodyparser
|
// Binds the request body to a struct.
|
||||||
|
// BodyParser supports decoding the following content types based on the Content-Type header:
|
||||||
|
// application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#bodyparser
|
||||||
func (ctx *Ctx) BodyParser(out interface{}) error {
|
func (ctx *Ctx) BodyParser(out interface{}) error {
|
||||||
// TODO : Query Params
|
// TODO : Query Params
|
||||||
ctype := getString(ctx.Fasthttp.Request.Header.ContentType())
|
ctype := getString(ctx.Fasthttp.Request.Header.ContentType())
|
||||||
@ -303,7 +325,9 @@ func (ctx *Ctx) BodyParser(out interface{}) error {
|
|||||||
return fmt.Errorf("BodyParser: cannot parse content-type: %v", ctype)
|
return fmt.Errorf("BodyParser: cannot parse content-type: %v", ctype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearCookie : https://fiber.wiki/context#clearcookie
|
// Expire a client cookie (or all cookies if left empty)
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#clearcookie
|
||||||
func (ctx *Ctx) ClearCookie(key ...string) {
|
func (ctx *Ctx) ClearCookie(key ...string) {
|
||||||
if len(key) > 0 {
|
if len(key) > 0 {
|
||||||
for i := range key {
|
for i := range key {
|
||||||
@ -318,7 +342,8 @@ func (ctx *Ctx) ClearCookie(key ...string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compress : https://fiber.wiki/context#compress
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/compression
|
||||||
func (ctx *Ctx) Compress(enable ...bool) {
|
func (ctx *Ctx) Compress(enable ...bool) {
|
||||||
log.Println("Warning: c.Compress() is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
log.Println("Warning: c.Compress() is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
||||||
ctx.compress = true
|
ctx.compress = true
|
||||||
@ -327,7 +352,9 @@ func (ctx *Ctx) Compress(enable ...bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cookie : https://fiber.wiki/context#cookie
|
// Set cookie by passing a cookie struct
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#cookie
|
||||||
func (ctx *Ctx) Cookie(cookie *Cookie) {
|
func (ctx *Ctx) Cookie(cookie *Cookie) {
|
||||||
fcookie := &fasthttp.Cookie{}
|
fcookie := &fasthttp.Cookie{}
|
||||||
fcookie.SetKey(cookie.Name)
|
fcookie.SetKey(cookie.Name)
|
||||||
@ -340,7 +367,9 @@ func (ctx *Ctx) Cookie(cookie *Cookie) {
|
|||||||
ctx.Fasthttp.Response.Header.SetCookie(fcookie)
|
ctx.Fasthttp.Response.Header.SetCookie(fcookie)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cookies : https://fiber.wiki/context#cookies
|
// Get cookie value by key
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#cookies
|
||||||
func (ctx *Ctx) Cookies(key ...string) (value string) {
|
func (ctx *Ctx) Cookies(key ...string) (value string) {
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
return ctx.Get(HeaderCookie)
|
return ctx.Get(HeaderCookie)
|
||||||
@ -348,6 +377,11 @@ func (ctx *Ctx) Cookies(key ...string) (value string) {
|
|||||||
return getString(ctx.Fasthttp.Request.Header.Cookie(key[0]))
|
return getString(ctx.Fasthttp.Request.Header.Cookie(key[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Transfers the file from path as an attachment.
|
||||||
|
// Typically, browsers will prompt the user for download.
|
||||||
|
// By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog).
|
||||||
|
// Override this default with the filename parameter.
|
||||||
|
//
|
||||||
// Download : https://fiber.wiki/context#download
|
// Download : https://fiber.wiki/context#download
|
||||||
func (ctx *Ctx) Download(file string, name ...string) {
|
func (ctx *Ctx) Download(file string, name ...string) {
|
||||||
filename := filepath.Base(file)
|
filename := filepath.Base(file)
|
||||||
@ -360,12 +394,17 @@ func (ctx *Ctx) Download(file string, name ...string) {
|
|||||||
ctx.SendFile(file)
|
ctx.SendFile(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns err that is passed via Next(err)
|
// This contains the error information that thrown by a panic or passed via the Next(err) method.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#error
|
||||||
func (ctx *Ctx) Error() error {
|
func (ctx *Ctx) Error() error {
|
||||||
return ctx.err
|
return ctx.err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format : https://fiber.wiki/context#format
|
// Performs content-negotiation on the Accept HTTP header. It uses Accepts to select a proper format.
|
||||||
|
// If the header is not specified or there is no proper format, text/plain is used.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#format
|
||||||
func (ctx *Ctx) Format(body interface{}) {
|
func (ctx *Ctx) Format(body interface{}) {
|
||||||
var b string
|
var b string
|
||||||
accept := ctx.Accepts("html", "json")
|
accept := ctx.Accepts("html", "json")
|
||||||
@ -390,22 +429,31 @@ func (ctx *Ctx) Format(body interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormFile : https://fiber.wiki/context#formfile
|
// MultipartForm files can be retrieved by name, the first file from the given key is returned.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#formfile
|
||||||
func (ctx *Ctx) FormFile(key string) (*multipart.FileHeader, error) {
|
func (ctx *Ctx) FormFile(key string) (*multipart.FileHeader, error) {
|
||||||
return ctx.Fasthttp.FormFile(key)
|
return ctx.Fasthttp.FormFile(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormValue : https://fiber.wiki/context#formvalue
|
// MultipartForm values can be retrieved by name, the first value from the given key is returned.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#formvalue
|
||||||
func (ctx *Ctx) FormValue(key string) (value string) {
|
func (ctx *Ctx) FormValue(key string) (value string) {
|
||||||
return getString(ctx.Fasthttp.FormValue(key))
|
return getString(ctx.Fasthttp.FormValue(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fresh : https://fiber.wiki/context#fresh
|
// Not implemented yet, pull requests are welcome!
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#fresh
|
||||||
func (ctx *Ctx) Fresh() bool {
|
func (ctx *Ctx) Fresh() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get : https://fiber.wiki/context#get
|
// Returns the HTTP request header specified by field.
|
||||||
|
// Field names are case-insensitive
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#get
|
||||||
func (ctx *Ctx) Get(key string) (value string) {
|
func (ctx *Ctx) Get(key string) (value string) {
|
||||||
if key == "referrer" {
|
if key == "referrer" {
|
||||||
key = "referer"
|
key = "referer"
|
||||||
@ -413,17 +461,23 @@ func (ctx *Ctx) Get(key string) (value string) {
|
|||||||
return getString(ctx.Fasthttp.Request.Header.Peek(key))
|
return getString(ctx.Fasthttp.Request.Header.Peek(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hostname : https://fiber.wiki/context#hostname
|
// Contains the hostname derived from the Host HTTP header.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#hostname
|
||||||
func (ctx *Ctx) Hostname() string {
|
func (ctx *Ctx) Hostname() string {
|
||||||
return getString(ctx.Fasthttp.URI().Host())
|
return getString(ctx.Fasthttp.URI().Host())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IP : https://fiber.wiki/context#Ip
|
// Returns the remote IP address of the request.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#Ip
|
||||||
func (ctx *Ctx) IP() string {
|
func (ctx *Ctx) IP() string {
|
||||||
return ctx.Fasthttp.RemoteIP().String()
|
return ctx.Fasthttp.RemoteIP().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPs : https://fiber.wiki/context#ips
|
// Returns an string slice of IP addresses specified in the X-Forwarded-For request header.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#ips
|
||||||
func (ctx *Ctx) IPs() []string {
|
func (ctx *Ctx) IPs() []string {
|
||||||
ips := strings.Split(ctx.Get(HeaderXForwardedFor), ",")
|
ips := strings.Split(ctx.Get(HeaderXForwardedFor), ",")
|
||||||
for i := range ips {
|
for i := range ips {
|
||||||
@ -432,7 +486,10 @@ func (ctx *Ctx) IPs() []string {
|
|||||||
return ips
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is : https://fiber.wiki/context#is
|
// Returns the matching content type,
|
||||||
|
// if the incoming request’s Content-Type HTTP header field matches the MIME type specified by the type parameter.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#is
|
||||||
func (ctx *Ctx) Is(extension string) (match bool) {
|
func (ctx *Ctx) Is(extension string) (match bool) {
|
||||||
if extension[0] != '.' {
|
if extension[0] != '.' {
|
||||||
extension = "." + extension
|
extension = "." + extension
|
||||||
@ -449,7 +506,10 @@ func (ctx *Ctx) Is(extension string) (match bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON : https://fiber.wiki/context#json
|
// Converts any interface or string to JSON using Jsoniter.
|
||||||
|
// This method also sets the content header to application/json.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#json
|
||||||
func (ctx *Ctx) JSON(json interface{}) error {
|
func (ctx *Ctx) JSON(json interface{}) error {
|
||||||
ctx.Fasthttp.Response.Header.SetContentType(MIMEApplicationJSON)
|
ctx.Fasthttp.Response.Header.SetContentType(MIMEApplicationJSON)
|
||||||
raw, err := jsoniter.Marshal(&json)
|
raw, err := jsoniter.Marshal(&json)
|
||||||
@ -462,7 +522,11 @@ func (ctx *Ctx) JSON(json interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONP : https://fiber.wiki/context#jsonp
|
// Sends a JSON response with JSONP support.
|
||||||
|
// This method is identical to JSON, except that it opts-in to JSONP callback support.
|
||||||
|
// By default, the callback name is simply callback.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#jsonp
|
||||||
func (ctx *Ctx) JSONP(json interface{}, callback ...string) error {
|
func (ctx *Ctx) JSONP(json interface{}, callback ...string) error {
|
||||||
raw, err := jsoniter.Marshal(&json)
|
raw, err := jsoniter.Marshal(&json)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -482,7 +546,9 @@ func (ctx *Ctx) JSONP(json interface{}, callback ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links : https://fiber.wiki/context#links
|
// Joins the links followed by the property to populate the response’s Link HTTP header field.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#links
|
||||||
func (ctx *Ctx) Links(link ...string) {
|
func (ctx *Ctx) Links(link ...string) {
|
||||||
h := ""
|
h := ""
|
||||||
for i, l := range link {
|
for i, l := range link {
|
||||||
@ -499,7 +565,10 @@ func (ctx *Ctx) Links(link ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locals : https://fiber.wiki/context#locals
|
// You can pass interface{} values under string keys scoped to the request
|
||||||
|
// and therefore available to all routes that match the request.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#locals
|
||||||
func (ctx *Ctx) Locals(key string, value ...interface{}) (val interface{}) {
|
func (ctx *Ctx) Locals(key string, value ...interface{}) (val interface{}) {
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return ctx.Fasthttp.UserValue(key)
|
return ctx.Fasthttp.UserValue(key)
|
||||||
@ -508,12 +577,16 @@ func (ctx *Ctx) Locals(key string, value ...interface{}) (val interface{}) {
|
|||||||
return value[0]
|
return value[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Location : https://fiber.wiki/context#location
|
// Sets the response Location HTTP header to the specified path parameter.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#location
|
||||||
func (ctx *Ctx) Location(path string) {
|
func (ctx *Ctx) Location(path string) {
|
||||||
ctx.Set(HeaderLocation, path)
|
ctx.Set(HeaderLocation, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method : https://fiber.wiki/context#method
|
// Contains a string corresponding to the HTTP method of the request: GET, POST, PUT and so on.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#method
|
||||||
func (ctx *Ctx) Method(override ...string) string {
|
func (ctx *Ctx) Method(override ...string) string {
|
||||||
if len(override) > 0 {
|
if len(override) > 0 {
|
||||||
ctx.method = override[0]
|
ctx.method = override[0]
|
||||||
@ -521,12 +594,18 @@ func (ctx *Ctx) Method(override ...string) string {
|
|||||||
return ctx.method
|
return ctx.method
|
||||||
}
|
}
|
||||||
|
|
||||||
// MultipartForm : https://fiber.wiki/context#multipartform
|
// Access multipart form entries, you can parse the binary with MultipartForm().
|
||||||
|
// This returns a map[string][]string, so given a key the value will be a string slice.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#multipartform
|
||||||
func (ctx *Ctx) MultipartForm() (*multipart.Form, error) {
|
func (ctx *Ctx) MultipartForm() (*multipart.Form, error) {
|
||||||
return ctx.Fasthttp.MultipartForm()
|
return ctx.Fasthttp.MultipartForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next : https://fiber.wiki/context#next
|
// Next executes the next method in the stack that matches the current route.
|
||||||
|
// You can pass an optional error for custom error handling.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#next
|
||||||
func (ctx *Ctx) Next(err ...error) {
|
func (ctx *Ctx) Next(err ...error) {
|
||||||
ctx.route = nil
|
ctx.route = nil
|
||||||
ctx.values = nil
|
ctx.values = nil
|
||||||
@ -536,12 +615,17 @@ func (ctx *Ctx) Next(err ...error) {
|
|||||||
ctx.app.nextRoute(ctx)
|
ctx.app.nextRoute(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OriginalURL : https://fiber.wiki/context#originalurl
|
// Contains the original request URL.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#originalurl
|
||||||
func (ctx *Ctx) OriginalURL() string {
|
func (ctx *Ctx) OriginalURL() string {
|
||||||
return getString(ctx.Fasthttp.Request.Header.RequestURI())
|
return getString(ctx.Fasthttp.Request.Header.RequestURI())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params : https://fiber.wiki/context#params
|
// Used to get the route parameters.
|
||||||
|
// Defaults to empty string "", if the param doesn't exist.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#params
|
||||||
func (ctx *Ctx) Params(key string) (value string) {
|
func (ctx *Ctx) Params(key string) (value string) {
|
||||||
if ctx.route.Params == nil {
|
if ctx.route.Params == nil {
|
||||||
return
|
return
|
||||||
@ -844,7 +928,9 @@ func (ctx *Ctx) Vary(fields ...string) {
|
|||||||
ctx.Set(HeaderVary, h)
|
ctx.Set(HeaderVary, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write : https://fiber.wiki/context#write
|
// Appends any input to the HTTP body response.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#write
|
||||||
func (ctx *Ctx) Write(bodies ...interface{}) {
|
func (ctx *Ctx) Write(bodies ...interface{}) {
|
||||||
for i := range bodies {
|
for i := range bodies {
|
||||||
switch body := bodies[i].(type) {
|
switch body := bodies[i].(type) {
|
||||||
@ -858,7 +944,10 @@ func (ctx *Ctx) Write(bodies ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XHR : https://fiber.wiki/context#xhr
|
// A Boolean property, that is true, if the request’s X-Requested-With header field is XMLHttpRequest,
|
||||||
|
// indicating that the request was issued by a client library (such as jQuery).
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/context#xhr
|
||||||
func (ctx *Ctx) XHR() bool {
|
func (ctx *Ctx) XHR() bool {
|
||||||
return ctx.Get(HeaderXRequestedWith) == "XMLHttpRequest"
|
return ctx.Get(HeaderXRequestedWith) == "XMLHttpRequest"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user