httputils

package module
v0.0.0-...-5fc12f5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 16 Imported by: 3

README

go-httputils

Go HTTP utils.

GoDoc

Install

go get github.com/koofr/go-httputils

Testing

go get -t
go test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRange = errors.New("invalid range")
View Source
var ErrRequestBodyTooLarge = errors.New("request body too large")
View Source
var ErrResponseNotHijacker = errors.New("response does not implement http.Hijacker")

Functions

func ForceDownload

func ForceDownload(filename string, h http.Header)

func MultipartRequestReader

func MultipartRequestReader(r *http.Request) (io.Reader, string, error)

func ParseRange

func ParseRange(s string, size int64) (spans []ioutils.FileSpan, hasEnd bool, err error)

func RequestJSONError

func RequestJSONError(r *http.Request, v interface{}, maxRequestJSONSize int) (jsonBytes []byte, err error)

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, r *http.Request, code int, v interface{}) error

func ResponseJSONBytes

func ResponseJSONBytes(w http.ResponseWriter, r *http.Request, code int, jsonBytes []byte) error

func UploadFile

func UploadFile(url string, reader io.Reader, name string, expectedStatus int, respValue interface{}) (res *http.Response, err error)

Types

type CallbackResponseWriter

type CallbackResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewCallbackResponseWriter

func NewCallbackResponseWriter(w http.ResponseWriter, beforeWriteHeader func()) *CallbackResponseWriter

func (*CallbackResponseWriter) Done

func (w *CallbackResponseWriter) Done()

func (*CallbackResponseWriter) Flush

func (w *CallbackResponseWriter) Flush()

func (*CallbackResponseWriter) Hijack

func (*CallbackResponseWriter) Write

func (w *CallbackResponseWriter) Write(b []byte) (int, error)

func (*CallbackResponseWriter) WriteHeader

func (w *CallbackResponseWriter) WriteHeader(statusCode int)

type CaptureResponseWriter

type CaptureResponseWriter struct {
	http.ResponseWriter
	StatusCode     int
	ResponseLength int64
	Start          time.Time
	WriteStart     time.Time
	Hijacked       bool
	HeaderWritten  bool
}

func NewCaptureResponseWriter

func NewCaptureResponseWriter(w http.ResponseWriter) *CaptureResponseWriter

func (*CaptureResponseWriter) Duration

func (w *CaptureResponseWriter) Duration() time.Duration

func (*CaptureResponseWriter) Flush

func (w *CaptureResponseWriter) Flush()

func (*CaptureResponseWriter) Hijack

func (*CaptureResponseWriter) Write

func (w *CaptureResponseWriter) Write(buf []byte) (int, error)

func (*CaptureResponseWriter) WriteDuration

func (w *CaptureResponseWriter) WriteDuration() time.Duration

func (*CaptureResponseWriter) WriteHeader

func (w *CaptureResponseWriter) WriteHeader(statusCode int)

type ErrInvalidContentType

type ErrInvalidContentType struct {
	Err error
}

func NewErrInvalidContentType

func NewErrInvalidContentType(err error) *ErrInvalidContentType

func (*ErrInvalidContentType) Error

func (e *ErrInvalidContentType) Error() string

func (*ErrInvalidContentType) Unwrap

func (e *ErrInvalidContentType) Unwrap() error

type ErrInvalidJSON

type ErrInvalidJSON struct {
	Err   error
	Bytes []byte
}

func NewErrInvalidJSON

func NewErrInvalidJSON(err error, bytes []byte) *ErrInvalidJSON

func (*ErrInvalidJSON) Error

func (e *ErrInvalidJSON) Error() string

func (*ErrInvalidJSON) Unwrap

func (e *ErrInvalidJSON) Unwrap() error

type ErrRequestJSON

type ErrRequestJSON struct {
	Err error
}

func NewErrRequestJSON

func NewErrRequestJSON(err error) *ErrRequestJSON

func (*ErrRequestJSON) Error

func (e *ErrRequestJSON) Error() string

func (*ErrRequestJSON) Unwrap

func (e *ErrRequestJSON) Unwrap() error

Jump to

Keyboard shortcuts

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