diff --git a/handler/main.go b/handler/main.go index 2689125..6bbd7dd 100644 --- a/handler/main.go +++ b/handler/main.go @@ -24,7 +24,24 @@ func getRequestParam(r *http.Request, key string, delete bool) string { return result } +func (w *fakeCloseReadCloser) Close() error { + return nil +} + +func (w *fakeCloseReadCloser) RealClose() error { + if w.ReadCloser == nil { + return nil + } + return w.ReadCloser.Close() +} + func Handler(w http.ResponseWriter, r *http.Request) { + if r.Body != nil { + r.Body = &fakeCloseReadCloser{r.Body} + defer func() { + _ = r.Body.(*fakeCloseReadCloser).RealClose() + }() + } proxy.ServeHTTP(w, r) } diff --git a/handler/structs.go b/handler/structs.go index 9e084e7..8dba3e0 100644 --- a/handler/structs.go +++ b/handler/structs.go @@ -1,3 +1,11 @@ package handler +import ( + "io" +) + type ctxKeyType struct{} + +type fakeCloseReadCloser struct { + io.ReadCloser +}