httpx

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	METHOD_GET                         = "GET"
	METHOD_POST                        = "POST"
	METHOD_TRACE                       = "TRACE"
	METHOD_DELETE                      = "DELETE"
	METHOD_PUT                         = "PUT"
	METHOD_OPTIONS                     = "OPTIONS"
	METHOD_HEAD                        = "HEAD"
	METHOD_CONNECT                     = "CONNECT"
	CONTENT_TYPE_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"
	CONTENT_TYPE_JSON                  = "application/json"
	CONTENT_TYPE_MULTIPART             = "multipart/form-data"
)
View Source
const (
	ContentTypePattern        = "^multipart/form-data; boundary=(.*)$"
	ContentDispositionPattern = "^Content-Disposition: form-data; name=\"([^\"]*)\"(; filename=\"([^\"]*)\".*)?$"
)

Variables

View Source
var (
	RegexContentTypePattern        = regexp.MustCompile(ContentTypePattern)
	RegexContentDispositionPattern = regexp.MustCompile(ContentDispositionPattern)
)

Functions

func ByteCopy

func ByteCopy(src []byte, start int, end int, cp []byte)

ByteCopy copies bytes

func Mock

func Mock() *mock

Mock returns an initialized mock.

func ServeContent

func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, content io.ReadSeeker, size int64)

if name is empty, filename is unknown. (used for mime type, before sniffing) if modtime.IsZero(), modtime is unknown. content must be seeked to the beginning of the file. The sizeFunc is called at most once. Its error, if any, is sent in the HTTP response.

func SetTTL

func SetTTL(timeout time.Duration)

SetTTL sets http client request timeout value. Default timeout value is 20s. A Timeout of zero means no timeout.

Types

type File

type File interface {
	io.Closer
	io.Reader
	io.Seeker
	Readdir(count int) ([]os.FileInfo, error)
	Stat() (os.FileInfo, error)
}

A File is returned by a FileSystem's Open method and can be served by the FileServer implementation.

The methods should behave the same as those on an *os.File.

type FileFormReader

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

FileFormReader processes io operation during file upload.

func (*FileFormReader) Read

func (reader *FileFormReader) Read(buff []byte) (int, error)

Read reads bytes from stream, if the buffer has bytes remain, read it first, then read from form body.

func (*FileFormReader) Unread

func (reader *FileFormReader) Unread(read []byte)

Unread return extra read bytes for next read.

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
}

A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.

type FileTransactionProcessor

type FileTransactionProcessor struct {
	Before  func() error
	Write   func(bs []byte) error
	Success func() error
	Error   func(err error)
}

FileTransactionProcessor is a model for processing one single file of a form.

type FileUploadHandler

type FileUploadHandler struct {
	Request *http.Request

	// call when read a plain text field.
	OnFormField func(paraName, paraValue string)
	// call when about begin to read file body from form, need to provide an io.WriteCloser to write file bytes.
	OnFileField func(paraName, fileName string) *FileTransactionProcessor
	// contains filtered or unexported fields
}

FileUploadHandler defines a handler for processing http file upload.

func (*FileUploadHandler) Parse

func (handler *FileUploadHandler) Parse() error

Parse begin to read request entity and parse form field

Jump to

Keyboard shortcuts

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