handle gzipped requests
This commit is contained in:
parent
13a4fe1c04
commit
9bcfa7a412
1 changed files with 9 additions and 2 deletions
11
main.go
11
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"compress/gzip"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -16,12 +17,18 @@ func requestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Printf("%s %s from %s", r.Method, r.RequestURI, r.RemoteAddr)
|
fmt.Printf("%s %s from %s", r.Method, r.RequestURI, r.RemoteAddr)
|
||||||
|
|
||||||
if *body {
|
if *body {
|
||||||
|
var requestbody []byte
|
||||||
|
|
||||||
r.Body = http.MaxBytesReader(w, r.Body, 1048576)
|
r.Body = http.MaxBytesReader(w, r.Body, 1048576)
|
||||||
body, err := io.ReadAll(r.Body)
|
if r.Header.Get("Content-Encoding") == "gzip" {
|
||||||
|
gzipreader, _ := gzip.NewReader(r.Body)
|
||||||
|
requestbody, _ = io.ReadAll(gzipreader)
|
||||||
|
}
|
||||||
|
requestbody, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "unable to read response", http.StatusBadRequest)
|
http.Error(w, "unable to read response", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n--- BODY ---\n%s\n", string(body))
|
fmt.Printf("\n--- BODY ---\n%s\n", string(requestbody))
|
||||||
}
|
}
|
||||||
|
|
||||||
if *header {
|
if *header {
|
||||||
|
|
Loading…
Reference in a new issue