reqdecoder

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2023 License: MIT Imports: 4 Imported by: 0

README

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)

Documentation

Overview

Package reqdecoder implements a request body decoder/decompressor. This package contains gzip and deflate decompression and supports custom decoders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDecoder

func AddDecoder(contentEncoding string, decoder decoderFunc)

AddDecoder adds new decoder to the list of decoders. contentEncoding should match "Content-Encoding" http header tag. decoder should return nil on error.

func RequestDecoder

func RequestDecoder(next http.Handler) http.Handler

RequestDecoder is decoding middleware function.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL