Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnResponse().DoFunc panic #318

Open
xenogenesi opened this issue Nov 29, 2018 · 0 comments
Open

OnResponse().DoFunc panic #318

xenogenesi opened this issue Nov 29, 2018 · 0 comments

Comments

@xenogenesi
Copy link

I used the yui minify example as base, from the content type I catch any json, do some business with it and then go on.

I believe the panic is caused by the GET of a very large file (like 4GB large, not .json) or maybe even a chunked request, anybody had the same problem? suggestions?

2018/11/29 20:19:35 [090] INFO: Received response 304 Not Modified
2018/11/29 20:19:35 [090] INFO: Copying response to client 304 Not Modified [304]
2018/11/29 20:19:35 [090] INFO: Copied 0 bytes to client error=<nil>
2018/11/29 20:20:19 http: panic serving 192.168.2.40:57825: runtime error: invalid memory address or nil pointer dereference
goroutine 566 [running]:
net/http.(*conn).serve.func1(0xc420440960)
	/usr/lib/go-1.10/src/net/http/server.go:1726 +0xd0
panic(0x6a7880, 0x889010)
	/usr/lib/go-1.10/src/runtime/panic.go:502 +0x229
main.main.func1(0x0, 0xc4202a6b40, 0x0)
	/home/alex/tmp/golang/gops4proxy/main.go:64 +0x46
github.com/elazarl/goproxy.FuncRespHandler.Handle(0x714028, 0x0, 0xc4202a6b40, 0xc42038fe30)
	/home/alex/go/src/github.com/elazarl/goproxy/actions.go:35 +0x3a
github.com/elazarl/goproxy.(*ProxyConds).Do.func1(0x0, 0xc4202a6b40, 0xc42011f830)
	/home/alex/go/src/github.com/elazarl/goproxy/dispatcher.go:284 +0x163
github.com/elazarl/goproxy.FuncRespHandler.Handle(0xc4200f19e0, 0x0, 0xc4202a6b40, 0x0)
	/home/alex/go/src/github.com/elazarl/goproxy/actions.go:35 +0x3a
github.com/elazarl/goproxy.(*ProxyHttpServer).filterResponse(0xc42012c000, 0x0, 0xc4202a6b40, 0x7375a0)
	/home/alex/go/src/github.com/elazarl/goproxy/proxy.go:73 +0x50
github.com/elazarl/goproxy.(*ProxyHttpServer).ServeHTTP(0xc42012c000, 0x73a680, 0xc42012a540, 0xc420414700)
	/home/alex/go/src/github.com/elazarl/goproxy/proxy.go:119 +0x789
net/http.serverHandler.ServeHTTP(0xc420080f70, 0x73a680, 0xc42012a540, 0xc420414700)
	/usr/lib/go-1.10/src/net/http/server.go:2697 +0xbc
net/http.(*conn).serve(0xc420440960, 0x73a900, 0xc4200112c0)
	/usr/lib/go-1.10/src/net/http/server.go:1830 +0x651
created by net/http.(*Server).Serve
	/usr/lib/go-1.10/src/net/http/server.go:2798 +0x27b

main.go::

 62          proxy.Verbose = *verbose
 63          proxy.OnResponse().DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
 64                  contentType := resp.Header.Get("Content-Type")
 65                  if strings.HasPrefix(contentType, "application/json") {
 66                          // 
 67                          ctx.Logf("** contentType: %s", string(contentType))
 68                          bodyContent, _ := ioutil.ReadAll(resp.Body)
	...
130                          }
131                          resp.Body = ioutil.NopCloser(bytes.NewReader(bodyContent))
132                  }
133                  return resp
134          })
135          log.Fatal(http.ListenAndServe(*addr, proxy))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant