You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

656 lines
29KB

  1. package iris
  2. import (
  3. "net/http"
  4. "path"
  5. "regexp"
  6. "github.com/kataras/iris/v12/cache"
  7. "github.com/kataras/iris/v12/context"
  8. "github.com/kataras/iris/v12/core/handlerconv"
  9. "github.com/kataras/iris/v12/core/host"
  10. "github.com/kataras/iris/v12/core/router"
  11. "github.com/kataras/iris/v12/hero"
  12. "github.com/kataras/iris/v12/view"
  13. )
  14. // SameSite attributes.
  15. const (
  16. SameSiteDefaultMode = http.SameSiteDefaultMode
  17. SameSiteLaxMode = http.SameSiteLaxMode
  18. SameSiteStrictMode = http.SameSiteStrictMode
  19. SameSiteNoneMode = http.SameSiteNoneMode
  20. )
  21. type (
  22. // Context is the middle-man server's "object" for the clients.
  23. //
  24. // A New context is being acquired from a sync.Pool on each connection.
  25. // The Context is the most important thing on the iris's http flow.
  26. //
  27. // Developers send responses to the client's request through a Context.
  28. // Developers get request information from the client's request by a Context.
  29. Context = *context.Context
  30. // ViewEngine is an alias of `context.ViewEngine`.
  31. // See HTML, Blocks, Django, Jet, Pug, Ace, Handlebars, Amber and e.t.c.
  32. ViewEngine = context.ViewEngine
  33. // UnmarshalerFunc a shortcut, an alias for the `context#UnmarshalerFunc` type
  34. // which implements the `context#Unmarshaler` interface for reading request's body
  35. // via custom decoders, most of them already implement the `context#UnmarshalerFunc`
  36. // like the json.Unmarshal, xml.Unmarshal, yaml.Unmarshal and every library which
  37. // follows the best practises and is aligned with the Go standards.
  38. //
  39. // See 'context#UnmarshalBody` for more.
  40. //
  41. // Example: https://github.com/kataras/iris/blob/master/_examples/request-body/read-custom-via-unmarshaler/main.go
  42. UnmarshalerFunc = context.UnmarshalerFunc
  43. // A Handler responds to an HTTP request.
  44. // It writes reply headers and data to the Context.ResponseWriter() and then return.
  45. // Returning signals that the request is finished;
  46. // it is not valid to use the Context after or concurrently with the completion of the Handler call.
  47. //
  48. // Depending on the HTTP client software, HTTP protocol version,
  49. // and any intermediaries between the client and the iris server,
  50. // it may not be possible to read from the Context.Request().Body after writing to the context.ResponseWriter().
  51. // Cautious handlers should read the Context.Request().Body first, and then reply.
  52. //
  53. // Except for reading the body, handlers should not modify the provided Context.
  54. //
  55. // If Handler panics, the server (the caller of Handler) assumes that the effect of the panic was isolated to the active request.
  56. // It recovers the panic, logs a stack trace to the server error log, and hangs up the connection.
  57. Handler = context.Handler
  58. // Filter is just a type of func(Context) bool which reports whether an action must be performed
  59. // based on the incoming request.
  60. //
  61. // See `NewConditionalHandler` for more.
  62. // An alias for the `context/Filter`.
  63. Filter = context.Filter
  64. // A Map is an alias of map[string]interface{}.
  65. Map = context.Map
  66. // User is a generic view of an authorized client.
  67. // See `Context.User` and `SetUser` methods for more.
  68. // An alias for the `context/User` type.
  69. User = context.User
  70. // SimpleUser is a simple implementation of the User interface.
  71. SimpleUser = context.SimpleUser
  72. // Problem Details for HTTP APIs.
  73. // Pass a Problem value to `context.Problem` to
  74. // write an "application/problem+json" response.
  75. //
  76. // Read more at: https://github.com/kataras/iris/wiki/Routing-error-handlers
  77. //
  78. // It is an alias of the `context#Problem` type.
  79. Problem = context.Problem
  80. // ProblemOptions the optional settings when server replies with a Problem.
  81. // See `Context.Problem` method and `Problem` type for more details.
  82. //
  83. // It is an alias of the `context#ProblemOptions` type.
  84. ProblemOptions = context.ProblemOptions
  85. // JSON the optional settings for JSON renderer.
  86. //
  87. // It is an alias of the `context#JSON` type.
  88. JSON = context.JSON
  89. // JSONReader holds the JSON decode options of the `Context.ReadJSON, ReadBody` methods.
  90. //
  91. // It is an alias of the `context#JSONReader` type.
  92. JSONReader = context.JSONReader
  93. // JSONP the optional settings for JSONP renderer.
  94. //
  95. // It is an alias of the `context#JSONP` type.
  96. JSONP = context.JSONP
  97. // ProtoMarshalOptions is a type alias for protojson.MarshalOptions.
  98. ProtoMarshalOptions = context.ProtoMarshalOptions
  99. // ProtoUnmarshalOptions is a type alias for protojson.UnmarshalOptions.
  100. ProtoUnmarshalOptions = context.ProtoUnmarshalOptions
  101. // XML the optional settings for XML renderer.
  102. //
  103. // It is an alias of the `context#XML` type.
  104. XML = context.XML
  105. // Markdown the optional settings for Markdown renderer.
  106. // See `Context.Markdown` for more.
  107. //
  108. // It is an alias of the `context#Markdown` type.
  109. Markdown = context.Markdown
  110. // Supervisor is a shortcut of the `host#Supervisor`.
  111. // Used to add supervisor configurators on common Runners
  112. // without the need of importing the `core/host` package.
  113. Supervisor = host.Supervisor
  114. // Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
  115. // Party could also be named as 'Join' or 'Node' or 'Group' , Party chosen because it is fun.
  116. //
  117. // Look the `core/router#APIBuilder` for its implementation.
  118. //
  119. // A shortcut for the `core/router#Party`, useful when `PartyFunc` is being used.
  120. Party = router.Party
  121. // APIContainer is a wrapper of a common `Party` featured by Dependency Injection.
  122. // See `Party.ConfigureContainer` for more.
  123. //
  124. // A shortcut for the `core/router#APIContainer`.
  125. APIContainer = router.APIContainer
  126. // ResultHandler describes the function type which should serve the "v" struct value.
  127. // See `APIContainer.UseResultHandler`.
  128. ResultHandler = hero.ResultHandler
  129. // DirOptions contains the optional settings that
  130. // `FileServer` and `Party#HandleDir` can use to serve files and assets.
  131. // A shortcut for the `router.DirOptions`, useful when `FileServer` or `HandleDir` is being used.
  132. DirOptions = router.DirOptions
  133. // DirCacheOptions holds the options for the cached file system.
  134. // See `DirOptions`.
  135. DirCacheOptions = router.DirCacheOptions
  136. // DirListRichOptions the options for the `DirListRich` helper function.
  137. // A shortcut for the `router.DirListRichOptions`.
  138. // Useful when `DirListRich` function is passed to `DirOptions.DirList` field.
  139. DirListRichOptions = router.DirListRichOptions
  140. // Attachments options for files to be downloaded and saved locally by the client.
  141. // See `DirOptions`.
  142. Attachments = router.Attachments
  143. // Dir implements FileSystem using the native file system restricted to a
  144. // specific directory tree, can be passed to the `FileServer` function
  145. // and `HandleDir` method. It's an alias of `http.Dir`.
  146. Dir = http.Dir
  147. // ExecutionRules gives control to the execution of the route handlers outside of the handlers themselves.
  148. // Usage:
  149. // Party#SetExecutionRules(ExecutionRules {
  150. // Done: ExecutionOptions{Force: true},
  151. // })
  152. //
  153. // See `core/router/Party#SetExecutionRules` for more.
  154. // Example: https://github.com/kataras/iris/tree/master/_examples/mvc/middleware/without-ctx-next
  155. ExecutionRules = router.ExecutionRules
  156. // ExecutionOptions is a set of default behaviors that can be changed in order to customize the execution flow of the routes' handlers with ease.
  157. //
  158. // See `ExecutionRules` and `core/router/Party#SetExecutionRules` for more.
  159. ExecutionOptions = router.ExecutionOptions
  160. // CookieOption is the type of function that is accepted on
  161. // context's methods like `SetCookieKV`, `RemoveCookie` and `SetCookie`
  162. // as their (last) variadic input argument to amend the end cookie's form.
  163. //
  164. // Any custom or builtin `CookieOption` is valid,
  165. // see `CookiePath`, `CookieCleanPath`, `CookieExpires` and `CookieHTTPOnly` for more.
  166. //
  167. // An alias for the `context.CookieOption`.
  168. CookieOption = context.CookieOption
  169. // Cookie is a type alias for the standard net/http Cookie struct type.
  170. // See `Context.SetCookie`.
  171. Cookie = http.Cookie
  172. // N is a struct which can be passed on the `Context.Negotiate` method.
  173. // It contains fields which should be filled based on the `Context.Negotiation()`
  174. // server side values. If no matched mime then its "Other" field will be sent,
  175. // which should be a string or []byte.
  176. // It completes the `context/context.ContentSelector` interface.
  177. //
  178. // An alias for the `context.N`.
  179. N = context.N
  180. // Locale describes the i18n locale.
  181. // An alias for the `context.Locale`.
  182. Locale = context.Locale
  183. // ErrPrivate if provided then the error saved in context
  184. // should NOT be visible to the client no matter what.
  185. // An alias for the `context.ErrPrivate`.
  186. ErrPrivate = context.ErrPrivate
  187. )
  188. // Constants for input argument at `router.RouteRegisterRule`.
  189. // See `Party#SetRegisterRule`.
  190. const (
  191. // RouteOverride replaces an existing route with the new one, the default rule.
  192. RouteOverride = router.RouteOverride
  193. // RouteSkip keeps the original route and skips the new one.
  194. RouteSkip = router.RouteSkip
  195. // RouteError log when a route already exists, shown after the `Build` state,
  196. // server never starts.
  197. RouteError = router.RouteError
  198. // RouteOverlap will overlap the new route to the previous one.
  199. // If the route stopped and its response can be reset then the new route will be execute.
  200. RouteOverlap = router.RouteOverlap
  201. )
  202. // Contains the enum values of the `Context.GetReferrer()` method,
  203. // shortcuts of the context subpackage.
  204. const (
  205. ReferrerInvalid = context.ReferrerInvalid
  206. ReferrerIndirect = context.ReferrerIndirect
  207. ReferrerDirect = context.ReferrerDirect
  208. ReferrerEmail = context.ReferrerEmail
  209. ReferrerSearch = context.ReferrerSearch
  210. ReferrerSocial = context.ReferrerSocial
  211. ReferrerNotGoogleSearch = context.ReferrerNotGoogleSearch
  212. ReferrerGoogleOrganicSearch = context.ReferrerGoogleOrganicSearch
  213. ReferrerGoogleAdwords = context.ReferrerGoogleAdwords
  214. )
  215. // NoLayout to disable layout for a particular template file
  216. // A shortcut for the `view#NoLayout`.
  217. const NoLayout = view.NoLayout
  218. var (
  219. // HTML view engine.
  220. // Shortcut of the view.HTML.
  221. HTML = view.HTML
  222. // Blocks view engine.
  223. // Can be used as a faster alternative of the HTML engine.
  224. // Shortcut of the view.Blocks.
  225. Blocks = view.Blocks
  226. // Django view engine.
  227. // Shortcut of the view.Django.
  228. Django = view.Django
  229. // Handlebars view engine.
  230. // Shortcut of the view.Handlebars.
  231. Handlebars = view.Handlebars
  232. // Pug view engine.
  233. // Shortcut of the view.Pug.
  234. Pug = view.Pug
  235. // Amber view engine.
  236. // Shortcut of the view.Amber.
  237. Amber = view.Amber
  238. // Jet view engine.
  239. // Shortcut of the view.Jet.
  240. Jet = view.Jet
  241. // Ace view engine.
  242. // Shortcut of the view.Ace.
  243. Ace = view.Ace
  244. )
  245. type (
  246. // ErrViewNotExist reports whether a template was not found in the parsed templates tree.
  247. ErrViewNotExist = context.ErrViewNotExist
  248. // FallbackViewFunc is a function that can be registered
  249. // to handle view fallbacks. It accepts the Context and
  250. // a special error which contains information about the previous template error.
  251. // It implements the FallbackViewProvider interface.
  252. //
  253. // See `Context.View` method.
  254. FallbackViewFunc = context.FallbackViewFunc
  255. // FallbackView is a helper to register a single template filename as a fallback
  256. // when the provided tempate filename was not found.
  257. FallbackView = context.FallbackView
  258. // FallbackViewLayout is a helper to register a single template filename as a fallback
  259. // layout when the provided layout filename was not found.
  260. FallbackViewLayout = context.FallbackViewLayout
  261. )
  262. // PrefixDir returns a new FileSystem that opens files
  263. // by adding the given "prefix" to the directory tree of "fs".
  264. //
  265. // Useful when having templates and static files in the same
  266. // bindata AssetFile method. This way you can select
  267. // which one to serve as static files and what for templates.
  268. // All view engines have a `RootDir` method for that reason too
  269. // but alternatively, you can wrap the given file system with this `PrefixDir`.
  270. //
  271. // Example: https://github.com/kataras/iris/blob/master/_examples/file-server/single-page-application/embedded-single-page-application/main.go
  272. func PrefixDir(prefix string, fs http.FileSystem) http.FileSystem {
  273. return &prefixedDir{prefix, fs}
  274. }
  275. type prefixedDir struct {
  276. prefix string
  277. fs http.FileSystem
  278. }
  279. func (p *prefixedDir) Open(name string) (http.File, error) {
  280. name = path.Join(p.prefix, name)
  281. return p.fs.Open(name)
  282. }
  283. var (
  284. // Compression is a middleware which enables
  285. // writing and reading using the best offered compression.
  286. // Usage:
  287. // app.Use (for matched routes)
  288. // app.UseRouter (for both matched and 404s or other HTTP errors).
  289. Compression = func(ctx Context) {
  290. ctx.CompressWriter(true)
  291. ctx.CompressReader(true)
  292. ctx.Next()
  293. }
  294. // MatchImagesAssets is a simple regex expression
  295. // that can be passed to the DirOptions.Cache.CompressIgnore field
  296. // in order to skip compression on already-compressed file types
  297. // such as images and pdf.
  298. MatchImagesAssets = regexp.MustCompile("((.*).pdf|(.*).jpg|(.*).jpeg|(.*).gif|(.*).tif|(.*).tiff)$")
  299. // MatchCommonAssets is a simple regex expression which
  300. // can be used on `DirOptions.PushTargetsRegexp`.
  301. // It will match and Push
  302. // all available js, css, font and media files.
  303. // Ideal for Single Page Applications.
  304. MatchCommonAssets = regexp.MustCompile("((.*).js|(.*).css|(.*).ico|(.*).png|(.*).ttf|(.*).svg|(.*).webp|(.*).gif)$")
  305. )
  306. var (
  307. // RegisterOnInterrupt registers a global function to call when CTRL+C/CMD+C pressed or a unix kill command received.
  308. //
  309. // A shortcut for the `host#RegisterOnInterrupt`.
  310. RegisterOnInterrupt = host.RegisterOnInterrupt
  311. // LimitRequestBodySize is a middleware which sets a request body size limit
  312. // for all next handlers in the chain.
  313. //
  314. // A shortcut for the `context#LimitRequestBodySize`.
  315. LimitRequestBodySize = context.LimitRequestBodySize
  316. // NewConditionalHandler returns a single Handler which can be registered
  317. // as a middleware.
  318. // Filter is just a type of Handler which returns a boolean.
  319. // Handlers here should act like middleware, they should contain `ctx.Next` to proceed
  320. // to the next handler of the chain. Those "handlers" are registered to the per-request context.
  321. //
  322. //
  323. // It checks the "filter" and if passed then
  324. // it, correctly, executes the "handlers".
  325. //
  326. // If passed, this function makes sure that the Context's information
  327. // about its per-request handler chain based on the new "handlers" is always updated.
  328. //
  329. // If not passed, then simply the Next handler(if any) is executed and "handlers" are ignored.
  330. // Example can be found at: _examples/routing/conditional-chain.
  331. //
  332. // A shortcut for the `context#NewConditionalHandler`.
  333. NewConditionalHandler = context.NewConditionalHandler
  334. // FileServer returns a Handler which serves files from a specific system, phyisical, directory
  335. // or an embedded one.
  336. // The first parameter is the directory, relative to the executable program.
  337. // The second optional parameter is any optional settings that the caller can use.
  338. //
  339. // See `Party#HandleDir` too.
  340. // Examples can be found at: https://github.com/kataras/iris/tree/master/_examples/file-server
  341. // A shortcut for the `router.FileServer`.
  342. FileServer = router.FileServer
  343. // DirList is the default `DirOptions.DirList` field.
  344. // Read more at: `core/router.DirList`.
  345. DirList = router.DirList
  346. // DirListRich can be passed to `DirOptions.DirList` field
  347. // to override the default file listing appearance.
  348. // Read more at: `core/router.DirListRich`.
  349. DirListRich = router.DirListRich
  350. // StripPrefix returns a handler that serves HTTP requests
  351. // by removing the given prefix from the request URL's Path
  352. // and invoking the handler h. StripPrefix handles a
  353. // request for a path that doesn't begin with prefix by
  354. // replying with an HTTP 404 not found error.
  355. //
  356. // Usage:
  357. // fileserver := iris.FileServer("./static_files", DirOptions {...})
  358. // h := iris.StripPrefix("/static", fileserver)
  359. // app.Get("/static/{file:path}", h)
  360. // app.Head("/static/{file:path}", h)
  361. StripPrefix = router.StripPrefix
  362. // FromStd converts native http.Handler, http.HandlerFunc & func(w, r, next) to context.Handler.
  363. //
  364. // Supported form types:
  365. // .FromStd(h http.Handler)
  366. // .FromStd(func(w http.ResponseWriter, r *http.Request))
  367. // .FromStd(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc))
  368. //
  369. // A shortcut for the `handlerconv#FromStd`.
  370. FromStd = handlerconv.FromStd
  371. // Cache is a middleware providing server-side cache functionalities
  372. // to the next handlers, can be used as: `app.Get("/", iris.Cache, aboutHandler)`.
  373. // It should be used after Static methods.
  374. // See `iris#Cache304` for an alternative, faster way.
  375. //
  376. // Examples can be found at: https://github.com/kataras/iris/tree/master/_examples/#caching
  377. Cache = cache.Handler
  378. // NoCache is a middleware which overrides the Cache-Control, Pragma and Expires headers
  379. // in order to disable the cache during the browser's back and forward feature.
  380. //
  381. // A good use of this middleware is on HTML routes; to refresh the page even on "back" and "forward" browser's arrow buttons.
  382. //
  383. // See `iris#StaticCache` for the opposite behavior.
  384. //
  385. // A shortcut of the `cache#NoCache`
  386. NoCache = cache.NoCache
  387. // StaticCache middleware for caching static files by sending the "Cache-Control" and "Expires" headers to the client.
  388. // It accepts a single input parameter, the "cacheDur", a time.Duration that it's used to calculate the expiration.
  389. //
  390. // If "cacheDur" <=0 then it returns the `NoCache` middleware instaed to disable the caching between browser's "back" and "forward" actions.
  391. //
  392. // Usage: `app.Use(iris.StaticCache(24 * time.Hour))` or `app.Use(iris.StaticCache(-1))`.
  393. // A middleware, which is a simple Handler can be called inside another handler as well, example:
  394. // cacheMiddleware := iris.StaticCache(...)
  395. // func(ctx iris.Context){
  396. // cacheMiddleware(ctx)
  397. // [...]
  398. // }
  399. //
  400. // A shortcut of the `cache#StaticCache`
  401. StaticCache = cache.StaticCache
  402. // Cache304 sends a `StatusNotModified` (304) whenever
  403. // the "If-Modified-Since" request header (time) is before the
  404. // time.Now() + expiresEvery (always compared to their UTC values).
  405. // Use this, which is a shortcut of the, `chache#Cache304` instead of the "github.com/kataras/iris/v12/cache" or iris.Cache
  406. // for better performance.
  407. // Clients that are compatible with the http RCF (all browsers are and tools like postman)
  408. // will handle the caching.
  409. // The only disadvantage of using that instead of server-side caching
  410. // is that this method will send a 304 status code instead of 200,
  411. // So, if you use it side by side with other micro services
  412. // you have to check for that status code as well for a valid response.
  413. //
  414. // Developers are free to extend this method's behavior
  415. // by watching system directories changes manually and use of the `ctx.WriteWithExpiration`
  416. // with a "modtime" based on the file modified date,
  417. // similar to the `HandleDir`(which sends status OK(200) and browser disk caching instead of 304).
  418. //
  419. // A shortcut of the `cache#Cache304`.
  420. Cache304 = cache.Cache304
  421. // CookieAllowReclaim accepts the Context itself.
  422. // If set it will add the cookie to (on `CookieSet`, `CookieSetKV`, `CookieUpsert`)
  423. // or remove the cookie from (on `CookieRemove`) the Request object too.
  424. //
  425. // A shortcut for the `context#CookieAllowReclaim`.
  426. CookieAllowReclaim = context.CookieAllowReclaim
  427. // CookieAllowSubdomains set to the Cookie Options
  428. // in order to allow subdomains to have access to the cookies.
  429. // It sets the cookie's Domain field (if was empty) and
  430. // it also sets the cookie's SameSite to lax mode too.
  431. //
  432. // A shortcut for the `context#CookieAllowSubdomains`.
  433. CookieAllowSubdomains = context.CookieAllowSubdomains
  434. // CookieSameSite sets a same-site rule for cookies to set.
  435. // SameSite allows a server to define a cookie attribute making it impossible for
  436. // the browser to send this cookie along with cross-site requests. The main
  437. // goal is to mitigate the risk of cross-origin information leakage, and provide
  438. // some protection against cross-site request forgery attacks.
  439. //
  440. // See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.
  441. //
  442. // A shortcut for the `context#CookieSameSite`.
  443. CookieSameSite = context.CookieSameSite
  444. // CookieSecure sets the cookie's Secure option if the current request's
  445. // connection is using TLS. See `CookieHTTPOnly` too.
  446. //
  447. // A shortcut for the `context#CookieSecure`.
  448. CookieSecure = context.CookieSecure
  449. // CookieHTTPOnly is a `CookieOption`.
  450. // Use it to set the cookie's HttpOnly field to false or true.
  451. // HttpOnly field defaults to true for `RemoveCookie` and `SetCookieKV`.
  452. //
  453. // A shortcut for the `context#CookieHTTPOnly`.
  454. CookieHTTPOnly = context.CookieHTTPOnly
  455. // CookiePath is a `CookieOption`.
  456. // Use it to change the cookie's Path field.
  457. //
  458. // A shortcut for the `context#CookiePath`.
  459. CookiePath = context.CookiePath
  460. // CookieCleanPath is a `CookieOption`.
  461. // Use it to clear the cookie's Path field, exactly the same as `CookiePath("")`.
  462. //
  463. // A shortcut for the `context#CookieCleanPath`.
  464. CookieCleanPath = context.CookieCleanPath
  465. // CookieExpires is a `CookieOption`.
  466. // Use it to change the cookie's Expires and MaxAge fields by passing the lifetime of the cookie.
  467. //
  468. // A shortcut for the `context#CookieExpires`.
  469. CookieExpires = context.CookieExpires
  470. // CookieEncoding accepts a value which implements `Encode` and `Decode` methods.
  471. // It calls its `Encode` on `Context.SetCookie, UpsertCookie, and SetCookieKV` methods.
  472. // And on `Context.GetCookie` method it calls its `Decode`.
  473. //
  474. // A shortcut for the `context#CookieEncoding`.
  475. CookieEncoding = context.CookieEncoding
  476. // IsErrEmptyJSON reports whether the given "err" is caused by a
  477. // Context.ReadJSON call when the request body
  478. // didn't start with { or it was totally empty.
  479. IsErrEmptyJSON = context.IsErrEmptyJSON
  480. // IsErrPath can be used at `context#ReadForm` and `context#ReadQuery`.
  481. // It reports whether the incoming error is type of `schema.ErrPath`,
  482. // which can be ignored when server allows unknown post values to be sent by the client.
  483. //
  484. // A shortcut for the `context#IsErrPath`.
  485. IsErrPath = context.IsErrPath
  486. // ErrEmptyForm is the type error which API users can make use of
  487. // to check if a form was empty on `Context.ReadForm`.
  488. //
  489. // A shortcut for the `context#ErrEmptyForm`.
  490. ErrEmptyForm = context.ErrEmptyForm
  491. // ErrEmptyFormField reports whether if form value is empty.
  492. // An alias of `context.ErrEmptyFormField`.
  493. ErrEmptyFormField = context.ErrEmptyFormField
  494. // ErrNotFound reports whether a key was not found, useful
  495. // on post data, versioning feature and others.
  496. // An alias of `context.ErrNotFound`.
  497. ErrNotFound = context.ErrNotFound
  498. // NewProblem returns a new Problem.
  499. // Head over to the `Problem` type godoc for more.
  500. //
  501. // A shortcut for the `context#NewProblem`.
  502. NewProblem = context.NewProblem
  503. // XMLMap wraps a map[string]interface{} to compatible xml marshaler,
  504. // in order to be able to render maps as XML on the `Context.XML` method.
  505. //
  506. // Example: `Context.XML(XMLMap("Root", map[string]interface{}{...})`.
  507. //
  508. // A shortcut for the `context#XMLMap`.
  509. XMLMap = context.XMLMap
  510. // ErrStopExecution if returned from a hero middleware or a request-scope dependency
  511. // stops the handler's execution, see _examples/dependency-injection/basic/middleware.
  512. ErrStopExecution = hero.ErrStopExecution
  513. // ErrHijackNotSupported is returned by the Hijack method to
  514. // indicate that Hijack feature is not available.
  515. //
  516. // A shortcut for the `context#ErrHijackNotSupported`.
  517. ErrHijackNotSupported = context.ErrHijackNotSupported
  518. // ErrPushNotSupported is returned by the Push method to
  519. // indicate that HTTP/2 Push support is not available.
  520. //
  521. // A shortcut for the `context#ErrPushNotSupported`.
  522. ErrPushNotSupported = context.ErrPushNotSupported
  523. // PrivateError accepts an error and returns a wrapped private one.
  524. // A shortcut for the `context#PrivateError`.
  525. PrivateError = context.PrivateError
  526. )
  527. // HTTP Methods copied from `net/http`.
  528. const (
  529. MethodGet = http.MethodGet
  530. MethodPost = http.MethodPost
  531. MethodPut = http.MethodPut
  532. MethodDelete = http.MethodDelete
  533. MethodConnect = http.MethodConnect
  534. MethodHead = http.MethodHead
  535. MethodPatch = http.MethodPatch
  536. MethodOptions = http.MethodOptions
  537. MethodTrace = http.MethodTrace
  538. // MethodNone is an iris-specific "virtual" method
  539. // to store the "offline" routes.
  540. MethodNone = router.MethodNone
  541. )
  542. // HTTP status codes as registered with IANA.
  543. // See: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml.
  544. // Raw Copy from the future(tip) net/http std package in order to recude the import path of "net/http" for the users.
  545. const (
  546. StatusContinue = http.StatusContinue
  547. StatusSwitchingProtocols = http.StatusSwitchingProtocols
  548. StatusProcessing = http.StatusProcessing
  549. StatusEarlyHints = http.StatusEarlyHints
  550. StatusOK = http.StatusOK
  551. StatusCreated = http.StatusCreated
  552. StatusAccepted = http.StatusAccepted
  553. StatusNonAuthoritativeInfo = http.StatusNonAuthoritativeInfo
  554. StatusNoContent = http.StatusNoContent
  555. StatusResetContent = http.StatusResetContent
  556. StatusPartialContent = http.StatusPartialContent
  557. StatusMultiStatus = http.StatusMultiStatus
  558. StatusAlreadyReported = http.StatusAlreadyReported
  559. StatusIMUsed = http.StatusIMUsed
  560. StatusMultipleChoices = http.StatusMultipleChoices
  561. StatusMovedPermanently = http.StatusMovedPermanently
  562. StatusFound = http.StatusFound
  563. StatusSeeOther = http.StatusSeeOther
  564. StatusNotModified = http.StatusNotModified
  565. StatusUseProxy = http.StatusUseProxy
  566. StatusTemporaryRedirect = http.StatusTemporaryRedirect
  567. StatusPermanentRedirect = http.StatusPermanentRedirect
  568. StatusBadRequest = http.StatusBadRequest
  569. StatusUnauthorized = http.StatusUnauthorized
  570. StatusPaymentRequired = http.StatusPaymentRequired
  571. StatusForbidden = http.StatusForbidden
  572. StatusNotFound = http.StatusNotFound
  573. StatusMethodNotAllowed = http.StatusMethodNotAllowed
  574. StatusNotAcceptable = http.StatusNotAcceptable
  575. StatusProxyAuthRequired = http.StatusProxyAuthRequired
  576. StatusRequestTimeout = http.StatusRequestTimeout
  577. StatusConflict = http.StatusConflict
  578. StatusGone = http.StatusGone
  579. StatusLengthRequired = http.StatusLengthRequired
  580. StatusPreconditionFailed = http.StatusPreconditionFailed
  581. StatusRequestEntityTooLarge = http.StatusRequestEntityTooLarge
  582. StatusPayloadTooRage = StatusRequestEntityTooLarge
  583. StatusRequestURITooLong = http.StatusRequestURITooLong
  584. StatusUnsupportedMediaType = http.StatusUnsupportedMediaType
  585. StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable
  586. StatusExpectationFailed = http.StatusExpectationFailed
  587. StatusTeapot = http.StatusTeapot
  588. StatusMisdirectedRequest = http.StatusMisdirectedRequest
  589. StatusUnprocessableEntity = http.StatusUnprocessableEntity
  590. StatusLocked = http.StatusLocked
  591. StatusFailedDependency = http.StatusFailedDependency
  592. StatusTooEarly = http.StatusTooEarly
  593. StatusUpgradeRequired = http.StatusUpgradeRequired
  594. StatusPreconditionRequired = http.StatusPreconditionRequired
  595. StatusTooManyRequests = http.StatusTooManyRequests
  596. StatusRequestHeaderFieldsTooLarge = http.StatusRequestHeaderFieldsTooLarge
  597. StatusUnavailableForLegalReasons = http.StatusUnavailableForLegalReasons
  598. // Unofficial Client Errors.
  599. StatusPageExpired = context.StatusPageExpired
  600. StatusBlockedByWindowsParentalControls = context.StatusBlockedByWindowsParentalControls
  601. StatusInvalidToken = context.StatusInvalidToken
  602. StatusTokenRequired = context.StatusTokenRequired
  603. //
  604. StatusInternalServerError = http.StatusInternalServerError
  605. StatusNotImplemented = http.StatusNotImplemented
  606. StatusBadGateway = http.StatusBadGateway
  607. StatusServiceUnavailable = http.StatusServiceUnavailable
  608. StatusGatewayTimeout = http.StatusGatewayTimeout
  609. StatusHTTPVersionNotSupported = http.StatusHTTPVersionNotSupported
  610. StatusVariantAlsoNegotiates = http.StatusVariantAlsoNegotiates
  611. StatusInsufficientStorage = http.StatusInsufficientStorage
  612. StatusLoopDetected = http.StatusLoopDetected
  613. StatusNotExtended = http.StatusNotExtended
  614. StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired
  615. // Unofficial Server Errors.
  616. StatusBandwidthLimitExceeded = context.StatusBandwidthLimitExceeded
  617. StatusInvalidSSLCertificate = context.StatusInvalidSSLCertificate
  618. StatusSiteOverloaded = context.StatusSiteOverloaded
  619. StatusSiteFrozen = context.StatusSiteFrozen
  620. StatusNetworkReadTimeout = context.StatusNetworkReadTimeout
  621. )
  622. // StatusText returns a text for the HTTP status code. It returns the empty
  623. // string if the code is unknown.
  624. //
  625. // Shortcut for core/router#StatusText.
  626. var StatusText = context.StatusText