本文整理汇总了Golang中github.com/cosiner/zerver.Request.Method方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Method方法的具体用法?Golang Request.Method怎么用?Golang Request.Method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cosiner/zerver.Request
的用法示例。
在下文中一共展示了Request.Method方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Filter
func (ri *RequestId) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if req.Method() == "GET" {
chain(req, resp)
return
}
reqId := req.Header(ri.HeaderName)
if reqId == "" {
if ri.PassingOnNoId {
chain(req, resp)
} else {
resp.ReportBadRequest()
resp.Send("error", ri.Error)
}
} else {
id := req.RemoteIP() + ":" + reqId
if err := ri.Store.Save(id); err == ErrRequestIDExist {
resp.ReportForbidden()
resp.Send("error", ri.ErrorOverlap)
} else if err != nil {
ri.logger.Warnln(err)
} else {
chain(req, resp)
ri.Store.Remove(id)
}
}
}
示例2: VerifyFor
func (x *Xsrf) VerifyFor(req zerver.Request) bool {
m := req.Method()
if !x.FilterGet && (m == "GET" || m == "HEAD" || m == "OPTIONS") {
return true
}
token := req.Header(_HEADER_XSRFTOKEN)
if token == "" {
token = req.Header(_HEADER_CSRFTOKEN)
if token == "" {
token = req.Param(_XSRF_PARAM_NAME)
if token == "" {
return false
}
}
}
data := x.verify(unsafe2.Bytes(token))
if data != nil {
x.Pool.Put(data)
t, ip, agent := x.TokenInfo.Unmarshal(data)
return t != -1 &&
t+x.Timeout >= time2.Now().Unix() &&
ip == req.RemoteIP() &&
agent == req.UserAgent()
}
return false
}
示例3: Filter
func (c *CORS) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
reqMethod := req.Header(_CORS_REQUESTMETHOD)
reqHeaders := req.Header(_CORS_REQUESTHEADERS)
if req.Method() == "OPTIONS" && (reqMethod != "" || reqHeaders != "") {
c.preflight(req, resp, reqMethod, reqHeaders)
} else {
c.filter(req, resp, chain)
}
}
示例4: Create
// Create xsrf token, used as zerver.HandleFunc
func (x *Xsrf) Create(req zerver.Request, resp zerver.Response) {
tokBytes, err := x.CreateFor(req)
if err == nil {
resp.ReportServiceUnavailable()
return
}
if req.Method() == "POST" {
resp.ReportCreated()
}
defer x.Pool.Put(tokBytes)
x.logger.Warnln(resp.Send("tokBytes", tokBytes))
}
示例5: Filter
func (l *Log) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if l.CountTime {
nano := time.Now().UnixNano()
chain(req, resp)
nano = time.Now().UnixNano() - nano
l.logger.Infoln(
time2.ToHuman(nano),
resp.Status(),
req.Method(),
req.URL().Path,
req.RemoteIP(),
req.UserAgent())
} else {
chain(req, resp)
l.logger.Infoln(
resp.Status(),
req.Method(),
req.URL().Path,
req.RemoteIP(),
req.UserAgent())
}
}
示例6: Filter
func (l *Log) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if l.CountTime {
now := time2.Now()
chain(req, resp)
cost := time2.Now().Sub(now)
l.logger.Infoln(
cost.String(),
resp.Status(),
req.Method(),
req.URL().Path,
req.RemoteIP(),
req.UserAgent())
} else {
chain(req, resp)
l.logger.Infoln(
resp.Status(),
req.Method(),
req.URL().Path,
req.RemoteIP(),
req.UserAgent())
}
}
示例7: Filter
func (j JSONP) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if req.Method() != "GET" {
chain(req, resp)
return
}
res, _ := req.ResourceMaster().Resource(resource.RES_JSON)
if res == nil {
resp.ReportNotAcceptable()
return
}
callback := req.Param(string(j))
if callback == "" {
resp.ReportBadRequest()
resp.Send("error", "no callback function")
return
}
resp.SetContentType(resource.RES_JSON, res)
_, err := resp.WriteString(callback)
if err != nil {
goto ERROR
}
_, err = resp.WriteString("(")
if err != nil {
goto ERROR
}
chain(req, resp)
_, err = resp.WriteString(")")
if err == nil {
return
}
ERROR:
req.Logger().Warnln(err)
}