Git Product home page Git Product logo

httpencoding's Introduction

httpencoding

-- import "vimagination.zapto.org/httpencoding"

Package httpencoding provides a function to deal with the Accept-Encoding header.

Usage

func ClearEncoding

func ClearEncoding(r *http.Request)

ClearEncoding removes the Accept-Encoding header so that any further attempts to establish an encoding will simply used the default, plain text, encoding.

Useful when you don't want a handler down the chain to also handle encoding.

func HandleEncoding

func HandleEncoding(r *http.Request, h Handler) bool

HandleEncoding will process the Accept-Encoding header and calls the given handler for each encoding until the handler returns true.

This function returns true when the Handler returns true, false otherwise

For the identity (plain text) encoding the encoding string will be the empty string.

The wildcard encoding (*) is currently treated as identity when there is no independent identity encoding specified; otherwise, it is ignored.

func InvalidEncoding

func InvalidEncoding(w http.ResponseWriter)

InvalidEncoding writes the 406 header.

type Encoding

type Encoding string

Encoding represents an encoding string as used by the client. Examples are gzip, br and deflate.

type Handler

type Handler interface {
	Handle(encoding Encoding) bool
}

Handler provides an interface to handle an encoding.

The encoding string (e.g. gzip, br, deflate) is passed to the handler, which is expected to return true if no more encodings are required and false otherwise.

The empty string "" is used to signify the identity encoding, or plain text.

type HandlerFunc

type HandlerFunc func(Encoding) bool

HandlerFunc wraps a func to make it satisfy the Handler interface.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(e Encoding) bool

Handle calls the underlying func.

httpencoding's People

Contributors

mjkwoolnough avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.