mirror of
https://github.com/astaxie/beego.git
synced 2024-11-01 01:20:56 +00:00
commit
8ce5b6cc52
@ -17,6 +17,7 @@ package beego
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@ -124,6 +125,7 @@ type ControllerInterface interface {
|
|||||||
Head()
|
Head()
|
||||||
Patch()
|
Patch()
|
||||||
Options()
|
Options()
|
||||||
|
Trace()
|
||||||
Finish()
|
Finish()
|
||||||
Render() error
|
Render() error
|
||||||
XSRFToken() string
|
XSRFToken() string
|
||||||
@ -188,6 +190,28 @@ func (c *Controller) Options() {
|
|||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trace adds a request function to handle Trace request.
|
||||||
|
// this method SHOULD NOT be overridden.
|
||||||
|
// https://tools.ietf.org/html/rfc7231#section-4.3.8
|
||||||
|
// The TRACE method requests a remote, application-level loop-back of
|
||||||
|
// the request message. The final recipient of the request SHOULD
|
||||||
|
// reflect the message received, excluding some fields described below,
|
||||||
|
// back to the client as the message body of a 200 (OK) response with a
|
||||||
|
// Content-Type of "message/http" (Section 8.3.1 of [RFC7230]).
|
||||||
|
func (c *Controller) Trace() {
|
||||||
|
ts := func(h http.Header) (hs string) {
|
||||||
|
for k, v := range h {
|
||||||
|
hs += fmt.Sprintf("\r\n%s: %s", k, v)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hs := fmt.Sprintf("\r\nTRACE %s %s%s\r\n", c.Ctx.Request.RequestURI, c.Ctx.Request.Proto, ts(c.Ctx.Request.Header))
|
||||||
|
c.Ctx.Output.Header("Content-Type", "message/http")
|
||||||
|
c.Ctx.Output.Header("Content-Length", fmt.Sprint(len(hs)))
|
||||||
|
c.Ctx.Output.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
|
c.Ctx.WriteString(hs)
|
||||||
|
}
|
||||||
|
|
||||||
// HandlerFunc call function with the name
|
// HandlerFunc call function with the name
|
||||||
func (c *Controller) HandlerFunc(fnname string) bool {
|
func (c *Controller) HandlerFunc(fnname string) bool {
|
||||||
if v, ok := c.methodMapping[fnname]; ok {
|
if v, ok := c.methodMapping[fnname]; ok {
|
||||||
|
@ -843,6 +843,8 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
execController.Patch()
|
execController.Patch()
|
||||||
case http.MethodOptions:
|
case http.MethodOptions:
|
||||||
execController.Options()
|
execController.Options()
|
||||||
|
case http.MethodTrace:
|
||||||
|
execController.Trace()
|
||||||
default:
|
default:
|
||||||
if !execController.HandlerFunc(runMethod) {
|
if !execController.HandlerFunc(runMethod) {
|
||||||
vc := reflect.ValueOf(execController)
|
vc := reflect.ValueOf(execController)
|
||||||
|
Loading…
Reference in New Issue
Block a user