mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -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
|
||||
Body string
|
||||
|
||||
refHash string
|
||||
resp *http.Response
|
||||
bodyRead bool
|
||||
refHash string
|
||||
resp *http.Response
|
||||
bodyRead bool
|
||||
bodyClear bool
|
||||
}
|
||||
|
||||
func NewJSResponse(res *http.Response) *JSResponse {
|
||||
|
@ -45,6 +46,7 @@ func NewJSResponse(res *http.Response) *JSResponse {
|
|||
Headers: headers,
|
||||
resp: res,
|
||||
bodyRead: false,
|
||||
bodyClear: false,
|
||||
}
|
||||
resp.UpdateHash()
|
||||
|
||||
|
@ -67,6 +69,9 @@ func (j *JSResponse) WasModified() bool {
|
|||
if j.bodyRead {
|
||||
// body was read
|
||||
return true
|
||||
} else if j.bodyClear {
|
||||
// body was cleared manually
|
||||
return true
|
||||
} else if j.Body != "" {
|
||||
// body was not read but just set
|
||||
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) {
|
||||
resp = goproxy.NewResponse(req, j.ContentType, j.Status, j.Body)
|
||||
if len(j.Headers) > 0 {
|
||||
|
@ -125,6 +135,7 @@ func (j *JSResponse) ReadBody() string {
|
|||
|
||||
j.Body = string(raw)
|
||||
j.bodyRead = true
|
||||
j.bodyClear = false
|
||||
// reset the response body to the original unread state
|
||||
j.resp.Body = ioutil.NopCloser(bytes.NewBuffer(raw))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue