Skip to content

Commit

Permalink
Merge pull request #1513 from dmwm/httpgo-sort
Browse files Browse the repository at this point in the history
Add sorting to HTTP headers for better readability
  • Loading branch information
arooshap authored Jul 18, 2024
2 parents 1d40588 + 538fadc commit 7f08b90
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docker/httpgo/httpgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"net/http"
"net/http/httputil"
"sort"
"strings"
)

func RequestHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -13,9 +15,17 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("TLS:", r.TLS)
fmt.Println("Header:", r.Header)

// get all HTTP headers and sort them out
var headers []string
for k, _ := range r.Header {
headers = append(headers, k)
}
sort.Strings(headers)

// print out all request headers
fmt.Fprintf(w, "%s %s %s \n", r.Method, r.URL, r.Proto)
for k, v := range r.Header {
for _, k := range headers {
v, _ := r.Header[k]
h := strings.ToLower(k)
if strings.Contains(h, "hmac") || strings.Contains(h, "cookie") {
continue
Expand Down

0 comments on commit 7f08b90

Please sign in to comment.