Back to / filters / serve

package serve

Latest Go to latest
Published: 1 day ago | Licenses: Apache-2.0, MIT | Module:


Package serve provides a wrapper of net/http.Handler to be used as a filter.


Package Files

func ServeHTTP

func ServeHTTP(ctx filters.FilterContext, h http.Handler)

Creates a response from a handler and a request.

It calls the handler's ServeHTTP method with an internal response writer that shares the status code, headers and the response body with the returned response. It blocks until the handler calls the response writer's WriteHeader, or starts writing the body, or returns. The written body is not buffered, but piped to the returned response's body.

Example, a simple file server:

var handler = http.StripPrefix(webRoot, http.FileServer(http.Dir(root)))

func (f *myFilter) Request(ctx filters.FilterContext) {
	serve.ServeHTTP(ctx, handler)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier