Skip to content

Commit

Permalink
Log the useragent string with quotes for better parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmv committed Jul 4, 2024
1 parent 4240033 commit e8c14c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion host/embedhost/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Run(flags *flag.FlagSet, args []string) {
http.Handle(servePath, http.StripPrefix(prefix, http.HandlerFunc(
func(w http.ResponseWriter, req *http.Request) {
fullPath := prefix + req.URL.String()
clientName := fmt.Sprintf("%v:%v (useragent: %v)",
clientName := fmt.Sprintf("%v:%v (useragent: %q)",
req.Header.Get("X-Forwarded-For"), req.Header.Get("X-Forwarded-For-Port"),
req.UserAgent())
if err := dir.CheckPasswordsFiles(w, req); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions portal/embedportal/http_proxyserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ func (p *httpProxy) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// server seems to return errors for empty URIs so there has to be something
// in there. The parsing code is too complex to guess what it could be.
http.Error(w, "Empty path requested.", http.StatusBadRequest)
log.Printf("%v (useragent: %v) requested an empty req.URL.Path. Raw URI: %v",
log.Printf("%v (useragent: %q) requested an empty req.URL.Path. Raw URI: %v",
req.RemoteAddr, req.UserAgent(), req.RequestURI)
return
}
fwd := p.selectForwarder(req.Host, req.URL.Path)
if fwd == nil {
log.Printf("%v (useragent: %v) requested unregistered path: %v%v",
log.Printf("%v (useragent: %q) requested unregistered path: %v%v",
req.RemoteAddr, req.UserAgent(), req.Host, req.URL.Path)
http.NotFound(w, req)
return
Expand Down Expand Up @@ -361,7 +361,7 @@ func makeChallengeHandler(webRoot string) (http.Handler, error) {
}
fileServer := http.FileServer(dir)
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
log.Printf("%v (useragent: %v) requested %v", req.RemoteAddr, req.UserAgent(), req.URL)
log.Printf("%v (useragent: %q) requested %v", req.RemoteAddr, req.UserAgent(), req.URL)
fileServer.ServeHTTP(w, req)
}), nil
}
Expand Down

0 comments on commit e8c14c8

Please sign in to comment.