feat: print request
This commit is contained in:
parent
a5ae937755
commit
8ead555bf2
17
server.go
17
server.go
|
@ -53,6 +53,8 @@ func NewRelayServer(cfg Config) (http.Handler, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RelayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *RelayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.printRequest(r)
|
||||||
|
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "", "/":
|
case "", "/":
|
||||||
uid, err := s.readUserID(r)
|
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) {
|
func (s *RelayServer) redirect(w http.ResponseWriter, loc string) {
|
||||||
nr, err := http.NewRequest(http.MethodGet, loc, nil)
|
nr, err := http.NewRequest(http.MethodGet, loc, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue