diff options
| author | Jeff Carr <[email protected]> | 2024-10-26 21:02:05 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-26 21:02:05 -0500 |
| commit | 65b61769117db371c4ec8fc0094d67b8c1075c1b (patch) | |
| tree | 68fd264a6a64f714acab2ceae2d727cfcd631389 /jsonClient.go | |
| parent | cedee6e88af2350130e0808a1af6d792e0bb98cc (diff) | |
dump unused junk
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'jsonClient.go')
| -rw-r--r-- | jsonClient.go | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/jsonClient.go b/jsonClient.go deleted file mode 100644 index 4dc9b10..0000000 --- a/jsonClient.go +++ /dev/null @@ -1,108 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" -) - -// RequestInfo holds the extracted data from http.Request -type RequestInfo struct { - Host string `json:"host"` - URL string `json:"url"` - Proto string `json:"proto"` - Addr string `json:"addr"` - Agent string `json:"agent"` - Headers map[string][]string `json:"headers"` - Cookies map[string]string `json:"cookies"` - QueryParams map[string][]string `json:"queryParams"` - // Add other fields as needed - Body string `json:"body"` -} - -// dumpClient returns a string with JSON formatted http.Request information -func dumpJsonClient(r *http.Request) (string, error) { - // Extracting Cookies - cookieMap := make(map[string]string) - for _, cookie := range r.Cookies() { - cookieMap[cookie.Name] = cookie.Value - } - - // Read the body (Ensure to do this first) - var bodyBytes []byte - if r.Body != nil { // Read the body if it's not nil - bodyBytes, _ = ioutil.ReadAll(r.Body) - r.Body.Close() // Close the body when done reading - r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) // Reset the body - } - - info := RequestInfo{ - Host: r.Host, - URL: r.URL.String(), - Proto: r.Proto, - Addr: r.RemoteAddr, - Agent: r.UserAgent(), - Headers: r.Header, - Cookies: cookieMap, - QueryParams: r.URL.Query(), - Body: string(bodyBytes), - } - - // Marshal the struct to a JSON string - jsonString, err := json.Marshal(info) - if err != nil { - return "", err // Return the error to the caller - } - - var jsonData interface{} - err = json.Unmarshal([]byte(jsonString), &jsonData) - if err != nil { - return "", err // Return the error to the caller - } - - formattedJSON, err := json.MarshalIndent(jsonData, "", " ") - if err != nil { - return "", err // Return the error to the caller - } - - return string(formattedJSON), nil -} - -/* -package main - -import ( - "bytes" - "encoding/json" - "io" - "io/ioutil" - "net/http" -) - -type RequestInfo struct { - // ... (other fields) - Body string `json:"body"` - // ... (other fields) -} - -func dumpClient(r *http.Request) (string, error) { - // ... (rest of your code to collect other request info) - - info := RequestInfo{ - // ... (other fields) - Body: string(bodyBytes), - // ... (other fields) - } - - // Marshal the struct to a JSON string - jsonString, err := json.Marshal(info) - if err != nil { - return "", err - } - - return string(jsonString), nil -} - -// ... (rest of your code) -*/ |
