Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package buffering provides http.Handler that buffers bodies of http requests to on-disk files before passing this request to child handler.
This may be useful if request is proxied to some backend that should read request as fast as possible and should not be bound by slow link of the client (i.e. Python backend).
Index ¶
Constants ¶
const DefaultBufSize = 32 * 1024 // 32K
    DefaultBufSize sets default max request body size which is buffered using in-memory buffers for newly created Handler. Use WithBufSize option to adjust Handler configuration.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns http.Handler wrapping original one; this handler first reads request body storing it to in-memory buffer or temporary file, then calls original handler to process request body directly from buffer or file.
If no options are given, Handler defaults to creating files in default temporary directory, has no max payload or concurrency limit and uses in-memory buffers for payloads not exceeding DefaultBufSize.
Types ¶
type Option ¶
type Option func(*handler)
Option modifies handler logic
func WithBufSize ¶
WithBufSize configures Handler to user in-memory buffers for payloads which do not exceed given size. Only bodies with Content-Length header are handled using in-memory buffers, chunked payloads fall back to files.
func WithDir ¶
WithDir configures Handler to use given directory to store temporary files. It doesn't check whether directory is accessible.
func WithFileLimit ¶
WithFileLimit limits max number of files Handler is allowed to keep opened. This may be useful to limit number of file descriptors and OS threads, since file IO in Go consume real threads. Optional wait duration specifies how long request would be waiting in the queue for available slot until giving up. If 0, wait time is not limited (until request is canceled).
func WithMaxSize ¶
WithMaxSize configures Handler to limit max allowed request body size. If request body exceeds given size, Handler replies with 413 Payload Too Large.
func WithRequiredContentLength ¶
func WithRequiredContentLength() Option
WithRequiredContentLength configures Handler to require Content-Length to be explicitly set for POST and PUT requests. POST and PUT requests without Content-Length header will get 411 Length Required response (RFC 7231, 6.5.10). This allows Handler to always use in-memory buffers when their size is sufficient.