mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
new: implemented JSResponse.ClearBody API (closes #272)
This commit is contained in:
parent
507d1b71e9
commit
f48feddd00
1 changed files with 14 additions and 3 deletions
|
@ -16,9 +16,10 @@ type JSResponse struct {
|
||||||
Headers []JSHeader
|
Headers []JSHeader
|
||||||
Body string
|
Body string
|
||||||
|
|
||||||
refHash string
|
refHash string
|
||||||
resp *http.Response
|
resp *http.Response
|
||||||
bodyRead bool
|
bodyRead bool
|
||||||
|
bodyClear bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJSResponse(res *http.Response) *JSResponse {
|
func NewJSResponse(res *http.Response) *JSResponse {
|
||||||
|
@ -45,6 +46,7 @@ func NewJSResponse(res *http.Response) *JSResponse {
|
||||||
Headers: headers,
|
Headers: headers,
|
||||||
resp: res,
|
resp: res,
|
||||||
bodyRead: false,
|
bodyRead: false,
|
||||||
|
bodyClear: false,
|
||||||
}
|
}
|
||||||
resp.UpdateHash()
|
resp.UpdateHash()
|
||||||
|
|
||||||
|
@ -67,6 +69,9 @@ func (j *JSResponse) WasModified() bool {
|
||||||
if j.bodyRead {
|
if j.bodyRead {
|
||||||
// body was read
|
// body was read
|
||||||
return true
|
return true
|
||||||
|
} else if j.bodyClear {
|
||||||
|
// body was cleared manually
|
||||||
|
return true
|
||||||
} else if j.Body != "" {
|
} else if j.Body != "" {
|
||||||
// body was not read but just set
|
// body was not read but just set
|
||||||
return true
|
return true
|
||||||
|
@ -105,6 +110,11 @@ func (j *JSResponse) RemoveHeader(name string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *JSResponse) ClearBody() {
|
||||||
|
j.Body = ""
|
||||||
|
j.bodyClear = true
|
||||||
|
}
|
||||||
|
|
||||||
func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
|
func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
|
||||||
resp = goproxy.NewResponse(req, j.ContentType, j.Status, j.Body)
|
resp = goproxy.NewResponse(req, j.ContentType, j.Status, j.Body)
|
||||||
if len(j.Headers) > 0 {
|
if len(j.Headers) > 0 {
|
||||||
|
@ -125,6 +135,7 @@ func (j *JSResponse) ReadBody() string {
|
||||||
|
|
||||||
j.Body = string(raw)
|
j.Body = string(raw)
|
||||||
j.bodyRead = true
|
j.bodyRead = true
|
||||||
|
j.bodyClear = false
|
||||||
// reset the response body to the original unread state
|
// reset the response body to the original unread state
|
||||||
j.resp.Body = ioutil.NopCloser(bytes.NewBuffer(raw))
|
j.resp.Body = ioutil.NopCloser(bytes.NewBuffer(raw))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue