Skip to content

Commit

Permalink
Merge pull request #6 from beclab/fix/proxy-response
Browse files Browse the repository at this point in the history
fix: proxy error with nil rawresponse
  • Loading branch information
eball authored Aug 6, 2024
2 parents 18ee772 + ec60e25 commit b1360e1
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions pkg/apiserver/v1alpha1/legacy/v1alpha1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ func (h *Handler) do(req *restful.Request, resp *restful.Response) {

switch proxyResp := proxyRespIntf.(type) {
case *resty.Response:
dump, err := httputil.DumpRequest(proxyResp.Request.RawRequest, true)
if err != nil {
klog.Error("dump request err: ", err)
dump, e := httputil.DumpRequest(proxyResp.Request.RawRequest, true)
if e != nil {
klog.Error("dump request err: ", e)
} else {
klog.Info("proxy request: ", string(dump))
}
if proxyResp.RawResponse == nil {
klog.Info("proxy error nil raw response: ", err)
api.HandleError(resp, req, err)
return
}

dump, err = httputil.DumpResponse(proxyResp.RawResponse, false)
if err != nil {
Expand All @@ -80,6 +85,11 @@ func (h *Handler) do(req *restful.Request, resp *restful.Response) {
resp.Write(proxyResp.Body())

case *serviceproxy.WsProxyResponse:
if proxyResp.RawResponse == nil {
klog.Info("ws proxy error: ", err)
api.HandleError(resp, req, err)
return
}
resp.WriteHeader(proxyResp.RawResponse.StatusCode)
resp.Write(proxyResp.Body)
}
Expand Down Expand Up @@ -130,12 +140,17 @@ func (h *Handler) doV2(req *restful.Request, resp *restful.Response) {
}
switch proxyResp := proxyRespIntf.(type) {
case *resty.Response:
dump, err := httputil.DumpRequest(proxyResp.Request.RawRequest, true)
if err != nil {
klog.Error("dump request err: ", err)
dump, e := httputil.DumpRequest(proxyResp.Request.RawRequest, true)
if e != nil {
klog.Error("dump request err: ", e)
} else {
klog.Info("proxy request: ", string(dump))
}
if proxyResp.RawResponse == nil {
klog.Info("proxy error nil raw response: ", err)
api.HandleError(resp, req, err)
return
}
dump, err = httputil.DumpResponse(proxyResp.RawResponse, false)
if err != nil {
klog.Error("dump response err: ", err)
Expand Down Expand Up @@ -168,6 +183,11 @@ func (h *Handler) doV2(req *restful.Request, resp *restful.Response) {
}

case *serviceproxy.WsProxyResponse:
if proxyResp.RawResponse == nil {
klog.Info("ws proxy error: ", err)
api.HandleError(resp, req, err)
return
}
resp.WriteHeader(proxyResp.RawResponse.StatusCode)
resp.Write(proxyResp.Body)
}
Expand Down

0 comments on commit b1360e1

Please sign in to comment.