clear
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func WriteRequest(w io.Writer, req *Request) {
|
||||
fmt.Fprintf(w, "%s %s %s\r\n", req.Method, req.Path, req.Protocol)
|
||||
|
||||
for _, header := range req.Headers {
|
||||
fmt.Fprintf(w, "%s: %s\r\n", header.Name, header.Value)
|
||||
}
|
||||
fmt.Fprintf(w, "\r\n")
|
||||
|
||||
if len(req.Body) > 0 {
|
||||
fmt.Fprintf(w, "%s\r\n", req.Body)
|
||||
}
|
||||
}
|
||||
|
||||
func DebugWrap(w io.Writer, req *Request, f func(w io.Writer, req *Request)) {
|
||||
buffer := &bytes.Buffer{}
|
||||
|
||||
f(buffer, req)
|
||||
|
||||
fmt.Println("----- Debug Info -----")
|
||||
fmt.Println(buffer.String())
|
||||
fmt.Println("----- Debug End Info -----")
|
||||
|
||||
w.Write(buffer.Bytes())
|
||||
}
|
||||
Reference in New Issue
Block a user