From 6eb7b291427b89e6466fb147c6aeb907ef50689c Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Sat, 22 Sep 2018 04:23:55 +0800 Subject: [PATCH] Add configuration option: debug_http_headers --- doh-client/client.go | 5 +++++ doh-client/config.go | 19 ++++++++++--------- doh-server/config.go | 19 ++++++++++--------- doh-server/server.go | 7 +++++++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/doh-client/client.go b/doh-client/client.go index 7326fca..84e3569 100644 --- a/doh-client/client.go +++ b/doh-client/client.go @@ -220,6 +220,11 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) { panic("Unknown request Content-Type") } + for _, header := range c.conf.DebugHTTPHeaders { + if value:= req.response.Header.Get(header); value != "" { + log.Printf("%s: %s\n", header, value) + } + } if req.err != nil { return } diff --git a/doh-client/config.go b/doh-client/config.go index 0018740..458bddb 100644 --- a/doh-client/config.go +++ b/doh-client/config.go @@ -30,15 +30,16 @@ import ( ) type config struct { - Listen []string `toml:"listen"` - UpstreamGoogle []string `toml:"upstream_google"` - UpstreamIETF []string `toml:"upstream_ietf"` - Bootstrap []string `toml:"bootstrap"` - Timeout uint `toml:"timeout"` - NoCookies bool `toml:"no_cookies"` - NoECS bool `toml:"no_ecs"` - NoIPv6 bool `toml:"no_ipv6"` - Verbose bool `toml:"verbose"` + Listen []string `toml:"listen"` + UpstreamGoogle []string `toml:"upstream_google"` + UpstreamIETF []string `toml:"upstream_ietf"` + Bootstrap []string `toml:"bootstrap"` + Timeout uint `toml:"timeout"` + NoCookies bool `toml:"no_cookies"` + NoECS bool `toml:"no_ecs"` + NoIPv6 bool `toml:"no_ipv6"` + Verbose bool `toml:"verbose"` + DebugHTTPHeaders []string `toml:"debug_http_headers"` } func loadConfig(path string) (*config, error) { diff --git a/doh-server/config.go b/doh-server/config.go index b168e99..6d0d745 100644 --- a/doh-server/config.go +++ b/doh-server/config.go @@ -30,15 +30,16 @@ import ( ) type config struct { - Listen []string `toml:"listen"` - Cert string `toml:"cert"` - Key string `toml:"key"` - Path string `toml:"path"` - Upstream []string `toml:"upstream"` - Timeout uint `toml:"timeout"` - Tries uint `toml:"tries"` - TCPOnly bool `toml:"tcp_only"` - Verbose bool `toml:"verbose"` + Listen []string `toml:"listen"` + Cert string `toml:"cert"` + Key string `toml:"key"` + Path string `toml:"path"` + Upstream []string `toml:"upstream"` + Timeout uint `toml:"timeout"` + Tries uint `toml:"tries"` + TCPOnly bool `toml:"tcp_only"` + Verbose bool `toml:"verbose"` + DebugHTTPHeaders []string `toml:"debug_http_headers"` } func loadConfig(path string) (*config, error) { diff --git a/doh-server/server.go b/doh-server/server.go index 0de19e4..e909bb1 100644 --- a/doh-server/server.go +++ b/doh-server/server.go @@ -112,6 +112,13 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) { const maxMemory = 32 << 20 // 32 MB r.ParseMultipartForm(maxMemory) } + + for _, header := range s.conf.DebugHTTPHeaders { + if value:= r.Header.Get(header); value != "" { + log.Printf("%s: %s\n", header, value) + } + } + contentType := r.Header.Get("Content-Type") if ct := r.FormValue("ct"); ct != "" { contentType = ct