33 lines
619 B
Go
33 lines
619 B
Go
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())
|
|
}
|