本文整理汇总了Golang中github.com/valyala/fasthttp.RequestHeader类的典型用法代码示例。如果您正苦于以下问题:Golang RequestHeader类的具体用法?Golang RequestHeader怎么用?Golang RequestHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestHeader类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetFromContextWithGlobalAndPrivateForwardedIps
func TestGetFromContextWithGlobalAndPrivateForwardedIps(t *testing.T) {
var ctx iris.Context
ctx.RequestCtx = &fasthttp.RequestCtx{}
header := fasthttp.RequestHeader{}
header.Add("X-Forwarded-For", "65.55.37.104, 100.64.0.0, 192.168.0.0, 192.0.0.0")
ctx.RequestCtx.Request.Header = header
ip := GetFromContext(&ctx)
assert.Equal(t, ip, "65.55.37.104", "Should be the first ip, which is the global ip address.")
}
开发者ID:vaot,项目名称:user_ip,代码行数:10,代码来源:user_ip_test.go
示例2: TestGetFromContextWithPrivateForwadedIp
func TestGetFromContextWithPrivateForwadedIp(t *testing.T) {
var ctx iris.Context
ctx.RequestCtx = &fasthttp.RequestCtx{}
header := fasthttp.RequestHeader{}
header.Add("X-Forwarded-For", "100.64.0.0, 192.168.0.0")
ctx.RequestCtx.Request.Header = header
ip := GetFromContext(&ctx)
assert.Equal(t, ip, "", "Should not find an ip address.")
}
开发者ID:vaot,项目名称:user_ip,代码行数:10,代码来源:user_ip_test.go
示例3: fetchFromUpstream
func fetchFromUpstream(h *fasthttp.RequestHeader, key []byte) *ybc.Item {
upstreamUrl := fmt.Sprintf("%s://%s%s", *upstreamProtocol, *upstreamHost, h.RequestURI())
var req fasthttp.Request
req.SetRequestURI(upstreamUrl)
var resp fasthttp.Response
err := upstreamClient.Do(&req, &resp)
if err != nil {
logRequestError(h, "Cannot make request for [%s]: [%s]", key, err)
return nil
}
if resp.StatusCode() != fasthttp.StatusOK {
logRequestError(h, "Unexpected status code=%d for the response [%s]", resp.StatusCode(), key)
return nil
}
contentType := string(resp.Header.ContentType())
if contentType == "" {
contentType = "application/octet-stream"
}
body := resp.Body()
contentLength := len(body)
itemSize := contentLength + len(contentType) + 1
txn, err := cache.NewSetTxn(key, itemSize, ybc.MaxTtl)
if err != nil {
logRequestError(h, "Cannot start set txn for response [%s], itemSize=%d: [%s]", key, itemSize, err)
return nil
}
if err = storeContentType(h, txn, contentType); err != nil {
txn.Rollback()
return nil
}
n, err := txn.Write(body)
if err != nil {
logRequestError(h, "Cannot read response [%s] body with size=%d to cache: [%s]", key, contentLength, err)
txn.Rollback()
return nil
}
if n != contentLength {
logRequestError(h, "Unexpected number of bytes copied=%d from response [%s] to cache. Expected %d", n, key, contentLength)
txn.Rollback()
return nil
}
item, err := txn.CommitItem()
if err != nil {
logRequestError(h, "Cannot commit set txn for response [%s], size=%d: [%s]", key, contentLength, err)
return nil
}
atomic.AddInt64(&stats.BytesReadFromUpstream, int64(n))
return item
}
开发者ID:valyala,项目名称:ybc,代码行数:54,代码来源:main.go
示例4: logRequestError
func logRequestError(h *fasthttp.RequestHeader, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
logMessage("%s - %s - %s. %s", h.RequestURI(), h.Referer(), h.UserAgent(), msg)
}
开发者ID:valyala,项目名称:ybc,代码行数:4,代码来源:main.go
示例5: getRequestHost
func getRequestHost(h *fasthttp.RequestHeader) []byte {
if *useClientRequestHost {
return h.Host()
}
return upstreamHostBytes
}
开发者ID:valyala,项目名称:ybc,代码行数:6,代码来源:main.go
注:本文中的github.com/valyala/fasthttp.RequestHeader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论