| 1 | package http_proxyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.16 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 6 | "io/ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/" |
| 7 | "net/httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 9 | |
| 10 | "github.com/elazarl/goproxyscip-go gomod github.com/elazarl/goproxy 8b0c20506380 `github.com/elazarl/goproxy`/" |
| 11 | ) |
| 12 | |
| 13 | type JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse# struct { |
| 14 | Statusscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Status. int |
| 15 | ContentTypescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ContentType. string |
| 16 | Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers. string |
| 17 | Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body. string |
| 18 | |
| 19 | refHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#refHash. string |
| 20 | respscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#resp. *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.16 `net/http`/Response# |
| 21 | bodyReadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyRead. bool |
| 22 | bodyClearscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyClear. bool |
| 23 | } |
| 24 | |
| 25 | func NewJSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/NewJSResponse().(res *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#) *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse# { |
| 26 | cType := "" |
| 27 | headers := "" |
| 28 | code := 200 |
| 29 | |
| 30 | if res != nil { |
| 31 | code = res.StatusCodescip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#StatusCode. |
| 32 | for name, values := range res.Headerscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Header. { |
| 33 | for _, value := range values { |
| 34 | headers += name + ": " + value + "\r\n" |
| 35 | |
| 36 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(name) == "content-type" { |
| 37 | cType = value |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | resp := &JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#{ |
| 44 | Statusscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Status.: code, |
| 45 | ContentTypescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ContentType.: cType, |
| 46 | Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers.: headers, |
| 47 | respscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#resp.: res, |
| 48 | bodyReadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyRead.: false, |
| 49 | bodyClearscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyClear.: false, |
| 50 | } |
| 51 | resp.UpdateHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#UpdateHash().() |
| 52 | |
| 53 | return resp |
| 54 | } |
| 55 | |
| 56 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) NewHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#NewHash().() string { |
| 57 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%d.%s.%s", j.Statusscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Status., j.ContentTypescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ContentType., j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers.) |
| 58 | } |
| 59 | |
| 60 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) UpdateHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#UpdateHash().() { |
| 61 | j.refHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#refHash. = j.NewHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#NewHash().() |
| 62 | } |
| 63 | |
| 64 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) WasModifiedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#WasModified().() bool { |
| 65 | if j.bodyReadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyRead. { |
| 66 | // body was read |
| 67 | return true |
| 68 | } else if j.bodyClearscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyClear. { |
| 69 | // body was cleared manually |
| 70 | return true |
| 71 | } else if j.Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body. != "" { |
| 72 | // body was not read but just set |
| 73 | return true |
| 74 | } |
| 75 | // check if any of the fields has been changed |
| 76 | return j.NewHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#NewHash().() != j.refHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#refHash. |
| 77 | } |
| 78 | |
| 79 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) GetHeaderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#GetHeader().(name, deflt string) string { |
| 80 | headers := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., "\r\n") |
| 81 | for i := 0; i < len(headers); i++ { |
| 82 | if headers[i] != "" { |
| 83 | header_parts := header_regexpscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/header_regexp..FindAllSubmatchscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#FindAllSubmatch().([]byte(headers[i]), 1) |
| 84 | if len(header_parts) != 0 && len(header_parts[0]) == 3 { |
| 85 | header_name := string(header_parts[0][1]) |
| 86 | header_value := string(header_parts[0][2]) |
| 87 | |
| 88 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(name) == stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(header_name) { |
| 89 | return header_value |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return deflt |
| 95 | } |
| 96 | |
| 97 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) SetHeaderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#SetHeader().(name, value string) { |
| 98 | name = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.16 strings/TrimSpace().(name) |
| 99 | value = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.16 strings/TrimSpace().(value) |
| 100 | |
| 101 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(name) == "content-type" { |
| 102 | j.ContentTypescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ContentType. = value |
| 103 | } |
| 104 | |
| 105 | headers := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., "\r\n") |
| 106 | for i := 0; i < len(headers); i++ { |
| 107 | if headers[i] != "" { |
| 108 | header_parts := header_regexpscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/header_regexp..FindAllSubmatchscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#FindAllSubmatch().([]byte(headers[i]), 1) |
| 109 | if len(header_parts) != 0 && len(header_parts[0]) == 3 { |
| 110 | header_name := string(header_parts[0][1]) |
| 111 | header_value := string(header_parts[0][2]) |
| 112 | |
| 113 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(name) == stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(header_name) { |
| 114 | old_header := header_name + ": " + header_value + "\r\n" |
| 115 | new_header := name + ": " + value + "\r\n" |
| 116 | j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers. = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., old_header, new_header, 1) |
| 117 | return |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers. += name + ": " + value + "\r\n" |
| 123 | } |
| 124 | |
| 125 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) RemoveHeaderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#RemoveHeader().(name string) { |
| 126 | headers := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., "\r\n") |
| 127 | for i := 0; i < len(headers); i++ { |
| 128 | if headers[i] != "" { |
| 129 | header_parts := header_regexpscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/header_regexp..FindAllSubmatchscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#FindAllSubmatch().([]byte(headers[i]), 1) |
| 130 | if len(header_parts) != 0 && len(header_parts[0]) == 3 { |
| 131 | header_name := string(header_parts[0][1]) |
| 132 | header_value := string(header_parts[0][2]) |
| 133 | |
| 134 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(name) == stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.16 strings/ToLower().(header_name) { |
| 135 | removed_header := header_name + ": " + header_value + "\r\n" |
| 136 | j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers. = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., removed_header, "", 1) |
| 137 | return |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) ClearBodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ClearBody().() { |
| 145 | j.Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body. = "" |
| 146 | j.bodyClearscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyClear. = true |
| 147 | } |
| 148 | |
| 149 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) ToResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ToResponse().(req *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.16 `net/http`/Request#) (resp *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#) { |
| 150 | resp = goproxyscip-go gomod github.com/elazarl/goproxy 8b0c20506380 `github.com/elazarl/goproxy`/.NewResponsescip-go gomod github.com/elazarl/goproxy 8b0c20506380 `github.com/elazarl/goproxy`/NewResponse().(req, j.ContentTypescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ContentType., j.Statusscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Status., j.Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body.) |
| 151 | |
| 152 | headers := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(j.Headersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Headers., "\r\n") |
| 153 | for i := 0; i < len(headers); i++ { |
| 154 | if headers[i] != "" { |
| 155 | header_parts := header_regexpscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/header_regexp..FindAllSubmatchscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#FindAllSubmatch().([]byte(headers[i]), 1) |
| 156 | if len(header_parts) != 0 && len(header_parts[0]) == 3 { |
| 157 | header_name := string(header_parts[0][1]) |
| 158 | header_value := string(header_parts[0][2]) |
| 159 | |
| 160 | resp.Headerscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Header..Addscip-go gomod github.com/golang/go/src go1.16 `net/http`/Header#Add().(header_name, header_value) |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | func (j *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) ReadBodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#ReadBody().() string { |
| 169 | defer j.respscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#resp..Bodyscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.16 io/Closer#Close().() |
| 170 | |
| 171 | raw, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadAllscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadAll().(j.respscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#resp..Bodyscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Body.) |
| 172 | if err != nil { |
| 173 | return "" |
| 174 | } |
| 175 | |
| 176 | j.Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body. = string(raw) |
| 177 | j.bodyReadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyRead. = true |
| 178 | j.bodyClearscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#bodyClear. = false |
| 179 | // reset the response body to the original unread state |
| 180 | j.respscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#resp..Bodyscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Body. = ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.NopCloserscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/NopCloser().(bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.16 bytes/NewBuffer().(raw)) |
| 181 | |
| 182 | return j.Bodyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#Body. |
| 183 | } |