response

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderContentType name of Content-Type header
	HeaderContentType = "content-type"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Response

type Response struct {
	StatusCode    int         // status code of response
	Headers       http.Header // headers for response
	ContentLength int64       // if buffered response contains length of buffer, for streams it equal to -1
	// contains filtered or unexported fields
}

Response is helper struct for wrapping different storage response

func New

func New(statusCode int, body io.ReadCloser) *Response

New create response object with io.ReadCloser

func NewBuf

func NewBuf(statusCode int, body []byte) *Response

NewBuf create response object from []byte

func NewError

func NewError(statusCode int, err error) *Response

NewError create response object from error

func NewNoContent

func NewNoContent(statusCode int) *Response

NewNoContent create response object without content

func NewString

func NewString(statusCode int, body string) *Response

NewString create response object from string

func (*Response) Close

func (r *Response) Close()

Close response reader

func (*Response) Copy

func (r *Response) Copy() (*Response, error)

Copy create complete response copy with headers and body

func (*Response) CopyBody

func (r *Response) CopyBody() ([]byte, error)

CopyBody read all content of response and returns it in []byte but doesn't change response object body

func (*Response) CopyHeadersFrom

func (r *Response) CopyHeadersFrom(src *Response)

CopyHeadersFrom copy all headers from src response but body is omitted

func (*Response) CopyWithStream

func (r *Response) CopyWithStream() (*Response, error)

CopyWithStream should be used with not buffered response that contain stream it try duplicate response stream for multiple readers

func (*Response) Error

func (r *Response) Error() error

Error returns error instance

func (*Response) HasError

func (r *Response) HasError() bool

HasError check if response contains error

func (*Response) IsBuffered

func (r *Response) IsBuffered() bool

IsBuffered check if response has access to original buffor

func (*Response) ReadBody

func (r *Response) ReadBody() ([]byte, error)

ReadBody reads all content of response and returns []byte Content of the response is changed Such response shouldn't be Send to client

func (*Response) Send

func (r *Response) Send(w http.ResponseWriter) error

Send write response to client using streaming

func (*Response) SendContent added in v0.3.0

func (r *Response) SendContent(req *http.Request, w http.ResponseWriter) error

SendContent use http.ServeContent to return response to client It can handle range and condition requests

func (*Response) Set

func (r *Response) Set(headerName string, headerValue string)

Set update response headers

func (*Response) SetContentType

func (r *Response) SetContentType(contentType string) *Response

SetContentType update content type header of response

func (*Response) SetDebug

func (r *Response) SetDebug(debug bool, obj *object.FileObject) *Response

SetDebug set flag indicating that response can including debug information

func (*Response) Stream

func (r *Response) Stream() io.ReadCloser

Stream return io.Reader interferace from correct response content

Jump to

Keyboard shortcuts

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