feat: print request

This commit is contained in:
zhanghelong 2022-12-03 00:59:43 +08:00
parent a5ae937755
commit 8ead555bf2
1 changed files with 17 additions and 0 deletions

View File

@ -53,6 +53,8 @@ func NewRelayServer(cfg Config) (http.Handler, error) {
}
func (s *RelayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.printRequest(r)
switch r.URL.Path {
case "", "/":
uid, err := s.readUserID(r)
@ -74,6 +76,21 @@ func (s *RelayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
func (s *RelayServer) printRequest(r *http.Request) {
log.Println("--- request start ---")
log.Println("path:")
log.Println(r.URL)
log.Println("headers:")
for k := range r.Header {
log.Println(k, "=", r.Header.Get(k))
}
log.Println("cookies:")
for _, c := range r.Cookies() {
log.Println(c.String())
}
log.Println("--- request end ---")
}
func (s *RelayServer) redirect(w http.ResponseWriter, loc string) {
nr, err := http.NewRequest(http.MethodGet, loc, nil)
if err != nil {