|
|
@ -6,13 +6,14 @@ import ( |
|
|
|
"compress/flate" |
|
|
|
"compress/flate" |
|
|
|
"compress/gzip" |
|
|
|
"compress/gzip" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"math" |
|
|
|
"math" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func httpDump(req *http.Request, resp *http.Response) { |
|
|
|
func httpDump(reqDump []byte, resp *http.Response) { |
|
|
|
defer resp.Body.Close() |
|
|
|
defer resp.Body.Close() |
|
|
|
var respStatusStr string |
|
|
|
var respStatusStr string |
|
|
|
respStatus := resp.StatusCode |
|
|
|
respStatus := resp.StatusCode |
|
|
@ -27,13 +28,26 @@ func httpDump(req *http.Request, resp *http.Response) { |
|
|
|
case 5: |
|
|
|
case 5: |
|
|
|
respStatusStr = Red("<--" + strconv.Itoa(respStatus)) |
|
|
|
respStatusStr = Red("<--" + strconv.Itoa(respStatus)) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println(Green("Request:")) |
|
|
|
|
|
|
|
fmt.Printf("%s %s %s\n", Blue(req.Method), req.RequestURI, respStatusStr) |
|
|
|
|
|
|
|
fmt.Printf("%s %s\n", Blue("RemoteAddr:"), req.RemoteAddr) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(Green("Request:"), respStatusStr) |
|
|
|
|
|
|
|
req, _ := ParseReq(reqDump) |
|
|
|
|
|
|
|
fmt.Printf("%s %s %s\n", Blue(req.Method), req.Host+req.RequestURI, respStatusStr) |
|
|
|
|
|
|
|
fmt.Printf("%s %s\n", Blue("RemoteAddr:"), req.RemoteAddr) |
|
|
|
for headerName, headerContext := range req.Header { |
|
|
|
for headerName, headerContext := range req.Header { |
|
|
|
fmt.Printf("%s: %s\n", Blue(headerName), headerContext) |
|
|
|
fmt.Printf("%s: %s\n", Blue(headerName), headerContext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Method == "POST" { |
|
|
|
|
|
|
|
fmt.Println(Green("POST Param:")) |
|
|
|
|
|
|
|
err := req.ParseForm() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
logger.Println("parseForm error:", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for k, v := range req.Form { |
|
|
|
|
|
|
|
fmt.Printf("\t%s: %s\n", Blue(k), v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
fmt.Println(Green("Response:")) |
|
|
|
fmt.Println(Green("Response:")) |
|
|
|
for headerName, headerContext := range resp.Header { |
|
|
|
for headerName, headerContext := range resp.Header { |
|
|
|
fmt.Printf("%s: %s\n", Blue(headerName), headerContext) |
|
|
|
fmt.Printf("%s: %s\n", Blue(headerName), headerContext) |
|
|
@ -71,3 +85,14 @@ func httpDump(req *http.Request, resp *http.Response) { |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%s%s%s\n", Black("####################"), Cyan("END"), Black("####################")) |
|
|
|
fmt.Printf("%s%s%s\n", Black("####################"), Cyan("END"), Black("####################")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ParseReq(b []byte) (*http.Request, error) { |
|
|
|
|
|
|
|
// func ReadRequest(b *bufio.Reader) (req *Request, err error) { return readRequest(b, deleteHostHeader) }
|
|
|
|
|
|
|
|
fmt.Println(string(b)) |
|
|
|
|
|
|
|
fmt.Println("-----------------------") |
|
|
|
|
|
|
|
var buf io.ReadWriter |
|
|
|
|
|
|
|
buf = new(bytes.Buffer) |
|
|
|
|
|
|
|
buf.Write(b) |
|
|
|
|
|
|
|
bufr := bufio.NewReader(buf) |
|
|
|
|
|
|
|
return http.ReadRequest(bufr) |
|
|
|
|
|
|
|
} |
|
|
|