Skip to content

Go middleware for decoding/decompressing request body

License

Notifications You must be signed in to change notification settings

anikinmd/reqdecoder

Repository files navigation

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)

About

Go middleware for decoding/decompressing request body

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages