mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
add quicktemplate example. Iris + Quicktemplate made easy 👍
Former-commit-id: b17fb21d8c1d5a73f9f9170f49ae0527870377a1
This commit is contained in:
@@ -210,23 +210,22 @@ func (h *routerHandler) HandleRequest(ctx context.Context) {
|
||||
}
|
||||
|
||||
if ctx.Application().ConfigurationReadOnly().GetFireMethodNotAllowed() {
|
||||
var methodAllowed string
|
||||
for i := range h.trees {
|
||||
t := h.trees[i]
|
||||
methodAllowed = t.Method // keep track of the allowed method of the last checked tree
|
||||
if ctx.Method() != methodAllowed {
|
||||
continue
|
||||
// a bit slower than previous implementation but @kataras let me to apply this change
|
||||
// because it's more reliable.
|
||||
//
|
||||
// if `Configuration#FireMethodNotAllowed` is kept as defaulted(false) then this function will not
|
||||
// run, therefore performance kept as before.
|
||||
if t.Nodes.Exists(path) {
|
||||
// RCF rfc2616 https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
||||
// The response MUST include an Allow header containing a list of valid methods for the requested resource.
|
||||
ctx.Header("Allow", t.Method)
|
||||
ctx.StatusCode(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.Method() != methodAllowed {
|
||||
// RCF rfc2616 https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
||||
// The response MUST include an Allow header containing a list of valid methods for the requested resource.
|
||||
ctx.Header("Allow", methodAllowed)
|
||||
ctx.StatusCode(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ctx.StatusCode(http.StatusNotFound)
|
||||
}
|
||||
|
||||
@@ -266,6 +266,15 @@ func (nodes Nodes) Find(path string, params *context.RequestParams) context.Hand
|
||||
return nil
|
||||
}
|
||||
|
||||
// Exists returns true if a node with that "path" exists,
|
||||
// otherise false.
|
||||
//
|
||||
// We don't care about parameters here.
|
||||
func (nodes Nodes) Exists(path string) bool {
|
||||
n, _ := nodes.findChild(path, nil)
|
||||
return n != nil && len(n.handlers) > 0
|
||||
}
|
||||
|
||||
func (nodes Nodes) findChild(path string, params []string) (*node, []string) {
|
||||
// println("request path: " + path)
|
||||
for _, n := range nodes {
|
||||
|
||||
Reference in New Issue
Block a user