mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 13:02:12 -07:00
refact: session/modules -> modules
This commit is contained in:
parent
da10147b7c
commit
64221a126d
13 changed files with 1 additions and 1 deletions
51
modules/http_proxy_js_request.go
Normal file
51
modules/http_proxy_js_request.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type JSHeader struct {
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
|
||||
type JSRequest struct {
|
||||
Method string
|
||||
Version string
|
||||
Path string
|
||||
Hostname string
|
||||
Headers []JSHeader
|
||||
Body string
|
||||
req *http.Request
|
||||
}
|
||||
|
||||
func NewJSRequest(req *http.Request) JSRequest {
|
||||
headers := make([]JSHeader, 0)
|
||||
for key, values := range req.Header {
|
||||
for _, value := range values {
|
||||
headers = append(headers, JSHeader{key, value})
|
||||
}
|
||||
}
|
||||
|
||||
return JSRequest{
|
||||
Method: req.Method,
|
||||
Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
|
||||
Path: req.URL.Path,
|
||||
Hostname: req.Host,
|
||||
Headers: headers,
|
||||
req: req,
|
||||
}
|
||||
}
|
||||
|
||||
func (j *JSRequest) ReadBody() string {
|
||||
raw, err := ioutil.ReadAll(j.req.Body)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
j.Body = string(raw)
|
||||
|
||||
return j.Body
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue