responseproxy

package
v0.0.0-...-b553abb Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package responseproxy provides various proxy functions for extending http.ResponseWriter.

TODO: Use idea from https://github.com/felixge/httpsnoop/blob/master/wrap.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedWriter

type BufferedWriter interface {
	http.ResponseWriter
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

BufferedWriter is a proxy around an http.ResponseWriter that allows you write the response body into a buffer instead of directly writing to the client. You must take care that the buffer gets written to the client. Calls to Flush() do not flush the buffer. Headers gets written directly to the client.

func WrapBuffered

func WrapBuffered(buf io.Writer, w http.ResponseWriter) BufferedWriter

WrapBuffered wraps an http.ResponseWriter, returning a proxy which only writes into the provided io.Writer.

type PipedWriter

type PipedWriter interface {
	http.ResponseWriter
	// Close must be called to terminate the internal goroutine.
	Close() error
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

PipedWriter is a proxy around an http.ResponseWriter that allows you write the response body into a pipe instead of directly writing to the client. You must take care that the pipe output (the reader) gets written to the client. Calls to Flush() do not flush the pipe. Headers gets written directly to the client.

func WrapPiped

func WrapPiped(iorf io.ReaderFrom, w http.ResponseWriter) PipedWriter

WrapPiped wraps an http.ResponseWriter, returning a proxy which pipes the writes to your ReaderFrom. You must call "defer Close()" to quite the internal goroutine.

type TeeWriter

type TeeWriter interface {
	http.ResponseWriter
	// Status returns the HTTP status of the request, or 0 if one has not
	// yet been sent.
	Status() int
	// BytesWritten returns the total number of bytes sent to the client.
	BytesWritten() int
	// Tee causes the response body to be written to the given io.Writer in
	// addition to proxying the writes through. Only one io.Writer can be
	// tee'd to at once: setting a second one will overwrite the first.
	// Writes will be sent to the proxy before being written to this
	// io.Writer. It is illegal for the tee'd writer to be modified
	// concurrently with writes.
	Tee(io.Writer)
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

TeeWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

func WrapTee

func WrapTee(w http.ResponseWriter) TeeWriter

WrapTee wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.

Jump to

Keyboard shortcuts

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