xhttp

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 10

Documentation

Index

Constants

View Source
const DefaultMaxFileSize = 100 * xbytes.MiB
View Source
const DefaultMaxInMemoryMultipartSize = 10 * xbytes.MiB // 10MiB

Variables

View Source
var (
	ErrHTTPBadRequest = errors.New("")
	ErrHTTPTooLarge   = errors.New("")
)
View Source
var DiscardMemory = 512 * xbytes.KiB
View Source
var MaxInMemoryMultipartSize = DefaultMaxInMemoryMultipartSize

Functions

func AsMaxBytesError added in v0.5.0

func AsMaxBytesError(err error) *http.MaxBytesError

func MaxBytesReader added in v0.5.0

func MaxBytesReader(r io.Reader, n int64) *maxBytesReader

MaxBytesReader is similar to http.MaxBytesReader but supporting for io.Reader instead of io.ReadCloser. It also doesn't support writing to any Writer when a MaxBytesError occurs.

func NewSniffReadCloser added in v0.4.0

func NewSniffReadCloser(r io.ReadCloser) *sniffReadCloser

func ParseHTTPRequest

func ParseHTTPRequest[T any](req *http.Request) (*T, error)

func ParseHTTPRequestWithLimitedSize added in v0.4.0

func ParseHTTPRequestWithLimitedSize[T any](req *http.Request, limitedSize int64) (*T, error)

func ParseURL

func ParseURL(s string) (*url.URL, error)

func WriteResponseJSON

func WriteResponseJSON(w http.ResponseWriter, code int, obj any) error

Types

type File added in v0.5.0

type File struct {
	// contains filtered or unexported fields
}

func NewFile added in v0.5.0

func NewFile(body SniffReadCloser, r *http.Request) *File

func NewFileFromMultipartFile added in v0.5.0

func NewFileFromMultipartFile(f multipart.File, header *multipart.FileHeader) *File

func (*File) AsBytes added in v0.5.0

func (f *File) AsBytes() (*bytes.Reader, error)

AsBytes converts File to bytes.Reader. It saves total file content into memory and suitable for small files.

func (*File) AsFile added in v0.5.0

func (f *File) AsFile() (io.ReadSeeker, error)

AsFile converts File to a ReadSeeker. The total file content is saved into a temporary file. It's suitable for large files.

func (*File) Close added in v0.5.0

func (f *File) Close() error

func (*File) ContentLength added in v0.5.0

func (f *File) ContentLength() int

func (*File) ContentType added in v0.5.0

func (f *File) ContentType(nsniff int64) (string, error)

func (*File) Reader added in v0.5.0

func (f *File) Reader() (io.Reader, error)

func (*File) SetMaxSize added in v0.5.0

func (f *File) SetMaxSize(s int64)

type FormDataRequest added in v0.4.0

type FormDataRequest interface {
	NumFiles() int
}

type SniffReadCloser added in v0.4.0

type SniffReadCloser interface {
	io.ReadCloser
	Sniffer
}

type Sniffer added in v0.4.0

type Sniffer interface {
	// Sniff is similar to Read but does not change the cursor.
	Sniff([]byte) (int, error)
}

Jump to

Keyboard shortcuts

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