Skip to content

Latest commit

 

History

History
33 lines (31 loc) · 942 Bytes

README.md

File metadata and controls

33 lines (31 loc) · 942 Bytes

codecov Go Report github.com/anikgithub.com/anikgithub.com/anikinmd/reqdecompinmd/reqdecompinmd/reqdecompCard

reqdecoder

Go middleware for decoding/decompressing request body

Features:

  • GZip
  • Deflate
  • Custom decoders

Usage:

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)