修复response_headers错误的问题

This commit is contained in:
Liujian
2023-12-26 16:22:57 +08:00
parent d9067a54a5
commit efca7db53f
3 changed files with 6 additions and 9 deletions

View File

@@ -143,9 +143,9 @@ func (ctx *cloneContext) SendTo(scheme string, node eoscContext.INode, timeout t
} }
beginTime := time.Now() beginTime := time.Now()
ctx.responseError = fasthttp_client.ProxyTimeout(scheme, rewriteHost, node, request, ctx.response.Response, timeout) ctx.responseError = fasthttp_client.ProxyTimeout(scheme, rewriteHost, node, request, ctx.response.Response, timeout)
var responseHeader *fasthttp.ResponseHeader var responseHeader fasthttp.ResponseHeader
if ctx.response.Response != nil { if ctx.response.Response != nil {
responseHeader = &ctx.response.Response.Header responseHeader = ctx.response.Response.Header
} }
agent := newRequestAgent(&ctx.proxyRequest, host, scheme, responseHeader, beginTime, time.Now()) agent := newRequestAgent(&ctx.proxyRequest, host, scheme, responseHeader, beginTime, time.Now())
if ctx.responseError != nil { if ctx.responseError != nil {

View File

@@ -149,9 +149,9 @@ func (ctx *HttpContext) SendTo(scheme string, node eoscContext.INode, timeout ti
} }
beginTime := time.Now() beginTime := time.Now()
ctx.response.responseError = fasthttp_client.ProxyTimeout(scheme, rewriteHost, node, request, &ctx.fastHttpRequestCtx.Response, timeout) ctx.response.responseError = fasthttp_client.ProxyTimeout(scheme, rewriteHost, node, request, &ctx.fastHttpRequestCtx.Response, timeout)
var responseHeader *fasthttp.ResponseHeader var responseHeader fasthttp.ResponseHeader
if ctx.response.Response != nil { if ctx.response.Response != nil {
responseHeader = &ctx.response.Response.Header responseHeader = ctx.response.Response.Header
} }
agent := newRequestAgent(&ctx.proxyRequest, host, scheme, responseHeader, beginTime, time.Now()) agent := newRequestAgent(&ctx.proxyRequest, host, scheme, responseHeader, beginTime, time.Now())
if ctx.response.responseError != nil { if ctx.response.responseError != nil {

View File

@@ -26,7 +26,7 @@ type requestAgent struct {
hostAgent *UrlAgent hostAgent *UrlAgent
remoteIP string remoteIP string
remotePort int remotePort int
originHeader *fasthttp.ResponseHeader originHeader fasthttp.ResponseHeader
headers http.Header headers http.Header
} }
@@ -38,9 +38,6 @@ func (a *requestAgent) ResponseHeaders() http.Header {
if a.headers != nil { if a.headers != nil {
return a.headers return a.headers
} }
if a.originHeader == nil {
return make(http.Header)
}
headers := make(http.Header) headers := make(http.Header)
a.originHeader.VisitAll(func(key, value []byte) { a.originHeader.VisitAll(func(key, value []byte) {
bytes.SplitN(value, []byte(":"), 2) bytes.SplitN(value, []byte(":"), 2)
@@ -85,7 +82,7 @@ func (a *requestAgent) setRemotePort(port int) {
a.remotePort = port a.remotePort = port
} }
func newRequestAgent(IRequest http_service.IRequest, host string, scheme string, header *fasthttp.ResponseHeader, beginTime, endTime time.Time) *requestAgent { func newRequestAgent(IRequest http_service.IRequest, host string, scheme string, header fasthttp.ResponseHeader, beginTime, endTime time.Time) *requestAgent {
return &requestAgent{IRequest: IRequest, host: host, scheme: scheme, beginTime: beginTime, endTime: endTime, originHeader: header} return &requestAgent{IRequest: IRequest, host: host, scheme: scheme, beginTime: beginTime, endTime: endTime, originHeader: header}
} }