lib/httpserver: print full requestURI in httpserver.Errorf

This should simplify debugging.
This commit is contained in:
Aliaksandr Valialkin
2021-07-07 12:59:03 +03:00
parent 4e87638877
commit ceda2b1df4
7 changed files with 55 additions and 52 deletions

View File

@@ -539,7 +539,8 @@ func GetQuotedRemoteAddr(r *http.Request) string {
func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) {
errStr := fmt.Sprintf(format, args...)
remoteAddr := GetQuotedRemoteAddr(r)
errStr = fmt.Sprintf("remoteAddr: %s; %s", remoteAddr, errStr)
requestURI := GetRequestURI(r)
errStr = fmt.Sprintf("remoteAddr: %s; requestURI: %s; %s", remoteAddr, requestURI, errStr)
logger.WarnfSkipframes(1, "%s", errStr)
// Extract statusCode from args
@@ -600,3 +601,21 @@ func WriteAPIHelp(w io.Writer, pathList [][2]string) {
fmt.Fprintf(w, "<a href=%q>%s</a> - %s<br/>", p, p, doc)
}
}
// GetRequestURI returns requestURI for r.
func GetRequestURI(r *http.Request) string {
requestURI := r.RequestURI
if r.Method != "POST" {
return requestURI
}
_ = r.ParseForm()
queryArgs := r.PostForm.Encode()
if len(queryArgs) == 0 {
return requestURI
}
delimiter := "?"
if strings.Contains(requestURI, delimiter) {
delimiter = "&"
}
return requestURI + delimiter + queryArgs
}