compresshandler

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 11 Imported by: 0

README

compresshandler

Go compress http handler. Just fire and forget.

GoDoc CI

Package provides methods to wrap http handler for auto decompress compressed data & auto compress response with prefered client compression.

Example

import (
        "net/http"

        "github.com/alexdyukov/compresshandler"
        "github.com/klauspost/compress/gzip"
        "github.com/klauspost/compress/zlib"
        "github.com/andybalholm/brotli"
)

func main() {
        echo := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                w.Write(r.Body)
        })

        compressConfig := compresshandler.Config{
                GzipLevel:        gzip.DefaultCompression,
                ZlibLevel:        zlib.DefaultCompression,
                BrotliLevel:      brotli.DefaultCompression,
                MinContentLength: 1400,
        }

        compress := compresshandler.NewNetHTTP(compressConfig)

        http.ListenAndServe(":8080", compress(echo))
}

TODOs

  • fasthttp and any other handler
  • Configurable content response type. We dont need to zip already zipped image or archives

License

MIT licensed. See the included LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetHTTP

func NewNetHTTP(config Config) func(next http.Handler) http.Handler

Types

type Config

type Config struct {
	GzipLevel        int
	ZlibLevel        int
	BrotliLevel      int
	MinContentLength int
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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