Go middleware for decoding/decompressing request body
Features:
- GZip
- Deflate
- Custom decoders
Basic:
http.Handle("/", reqdecoder.RequestDecoder(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
...
w.WriteHeader(http.StatusOK)
})))
Using chi:
r := chi.NewRouter()
r.Use(reqdecoder.RequestDecoder)
Custom decoder:
// Decoder should return nil on error
func customDecoder(reader io.ReadCloser) io.ReadCloser {
...
return newReader
}
...
reqdecoder.AddDecoder("customContentType", customDecoder)