From 9ba9cb8c52e7eb87eac987cc84cfb5b19659aaa6 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 22 Feb 2018 13:40:04 +0100 Subject: [PATCH] fix: resetting response and request Body to unread state (fixes #65) --- modules/http_proxy_js_request.go | 3 +++ modules/http_proxy_js_response.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/modules/http_proxy_js_request.go b/modules/http_proxy_js_request.go index 63a97ee2..17741d3f 100644 --- a/modules/http_proxy_js_request.go +++ b/modules/http_proxy_js_request.go @@ -1,6 +1,7 @@ package modules import ( + "bytes" "fmt" "io/ioutil" "net/http" @@ -61,6 +62,8 @@ func (j *JSRequest) ReadBody() string { } j.Body = string(raw) + // reset the request body to the original unread state + j.req.Body = ioutil.NopCloser(bytes.NewBuffer(raw)) return j.Body } diff --git a/modules/http_proxy_js_response.go b/modules/http_proxy_js_response.go index 83dfc069..ea372e99 100644 --- a/modules/http_proxy_js_response.go +++ b/modules/http_proxy_js_response.go @@ -1,6 +1,7 @@ package modules import ( + "bytes" "fmt" "io/ioutil" "net/http" @@ -99,6 +100,8 @@ func (j *JSResponse) ReadBody() string { j.Body = string(raw) j.bodyRead = true + // reset the request body to the original unread state + j.resp.Body = ioutil.NopCloser(bytes.NewBuffer(raw)) return j.Body }