草庐IT

request-headers

全部标签

http - 在重定向和代理上转到 http.Request header

https://groups.google.com/forum/#!topic/golang-nuts/OwGvopYXpwE正如在此线程中所见,当http.Client向重定向发送请求时,header会重置。有一个解决方法,如:client.CheckRedirect=func(req*http.Request,via[]*http.Request)error{iflen(via)>=10{returnfmt.Errorf("toomanyredirects")}iflen(via)==0{returnnil}forattr,val:=rangevia[0].Header{if_,o

api - 获取 URL 时转到 header

当我用Python编写程序并使用urllib发布请求时,我的header将作为Python-urllib/3.4发送到服务器当使用Go程序访问API时,默认情况下向服务器发送哪些HTTPheader? 最佳答案 例如,如果您只是执行一个http.Get,那么就User-Agent:Go-http-client/1.1Accept-Encoding:gzip 关于api-获取URL时转到header,我们在StackOverflow上找到一个类似的问题: htt

http - 即使响应没有缓存 header ,文件也会被浏览器缓存

varepoch=time.Unix(0,0).Format(time.RFC1123)varheaders=map[string]string{"Expires":epoch,"Cache-Control":"no-cache,private,max-age=0","Pragma":"no-cache","X-Accel-Expires":"0",}log.Errorln("nocacheheader")fork,v:=rangeheaders{rw.Header().Set(k,v)}http.ServeFile(rw,req,path)我的服务器端有上面的代码块来处理文件请求。但

amazon-web-services - 如何使用 Go 在 AWS S3 中设置 If-Modified-Since header

我有一个从S3下载文件的功能。它有效但不识别IfModifiedSince选项。下面的函数在本地查找同名文件,如果存在,则将time.Time对象设置为修改日期和时间。然后在对S3的请求中使用它,以便仅在文件自那时以来被修改后才下载该文件。funcDownloadS3Media(filenamestring,mediaDirectorystring,bucketstring,c*configuration.Configuration)(deststring,bytesint64,errerror){os.Setenv("AWS_ACCESS_KEY_ID",c.AWS_ACCESS_K

http - HTTP 代理是否应该将 Content-Encoding header 复制回客户端?

据说Transport会自动处理Content-Encoding(就像从resp.Body读取时自动解压)。也有人说,Content-Encoding是端到端的HTTPheader,而不是逐跳的。因此,如果代理将Content-Encoding复制回客户端的响应header,并且此代理还io.Copy上游响应主体(可能会自动解压,因为io.Copy会从resp.Body中读取),会不会和client不一致?(Content-Encoding从上游响应中复制,但正文已解压) 最佳答案 一般来说,Content-Encoding响应头不

Golang 在 http.Request 中跟踪请求 'body'

这个问题在这里已经有了答案:Readingbodyofhttp.Requestwithoutmodifyingrequeststate?(2个答案)关闭6年前。我的错误在这里得到了很好的解释:https://github.com/golang/go/issues/17088不知道是不是对http包的概念理解有误,我在发送请求后没有返回请求的“body”(我的POST请求发送的参数)(client.Do)。..示例:funcshowRequestBody(r*http.Request){fmt.Println(r)fmt.Println(r.Body)}给我一​​张空map,或者当我这样

go - http.Request 在部署到 appengine 时有未定义的字段

我正在开发一个网络应用程序,我依赖于以下代码进行身份验证(我正在使用github.com/dgrijalva/jwt-go包):funcValidateProtectedPage(protectedPagehttp.HandlerFunc)http.HandlerFunc{returnhttp.HandlerFunc(func(reshttp.ResponseWriter,req*http.Request){//IfnoAuthcookieissetthenreturna404notfoundcookie,err:=req.Cookie("Auth")iferr!=nil{Forbid

angular - header http 未传送到我的 API

我正在Go中开发一个安静的API,在Angular中开发我的前端(没有AngularJS),但是当我在Angular中从我的Web应用程序调用我的API时,我在后端看不到我的header,在特殊情况下我的授权header,因为我的API具有基于JWT的身份验证。另外我想提一下,我正在使用Postman和GoRequest客户端来测试我的应用程序,并且我的header在我的API中交付没有问题。下面附上我的后端的CORS和来self的前端的API调用。我的后端:funcCors()gin.HandlerFunc{log.Println("CORSMiddleware")returnfun

google-app-engine - 如何在 Google App Engine Standard Env for Go 中获取 request.RemoteAddr 和 X-AppEngine-Country、Region 等的输出?

我有一个在GoogleAppEngine标准环境中运行的服务,该服务是用Go编写的,配置为在部署时使用最新的运行时(api_version:go1-当前为Go1.8)。在这项服务中,我出于各种目的检查请求header。funcextractHeaders(reshttp.ResponseWriter,req*http.Request){ctx:=appengine.NewContext(req)clientIPAddress,_,_:=net.SplitHostPort(req.RemoteAddr)//Outputisblankcountry:=req.Header.Get("X-A

go - 在 go AuthFromMD 中,始终期望将授权作为 header 名称。我怎样才能覆盖它。

我正在使用github.com/grpc-ecosystem/go-grpc-middleware/util/metautils包来提取header,参见LinktoAuthFromMDimplementation我确信我可以覆盖AuthFromMD并拥有我自己的header名称而不是authorization。但事实证明是var:=metautils.ExtractIncoming(ctx).Get(headerAuthorize)这个方法调用总是期望headerAuthorize是authorization。或者它正在抛出错误。我的用例是具有不同的HeaderNames,因此我可以