httpx

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrefix

func AppendPrefix(prefix string, hh http.Handler) http.Handler

AppendPrefix returns a handler that serves HTTP requests by appending the given prefix from the request URL's Path (and RawPath if set) and invoking the handler hh.

func CopyMultipartFile added in v1.0.13

func CopyMultipartFile(file *multipart.FileHeader, dst io.Writer) error

CopyMultipartFile read multipart file to the specific buffer 'dst'.

func Dir

func Dir(root string, browsable ...bool) http.FileSystem

Dir returns a http.FileSystem that can be used by http.FileServer(). if browsable == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

func FS

func FS(fsys fs.FS, browsable ...bool) http.FileSystem

FS returns a http.FileSystem that can be used by http.FileServer(). if browsable == true, then it works the same as http.FS() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

func FileServer added in v1.0.13

func FileServer(prefix string, hfs http.FileSystem, filePath string) http.Handler

func FixedModTimeFS

func FixedModTimeFS(hfs http.FileSystem, mt time.Time) http.FileSystem

FixedModTimeFS returns a FileSystem with fixed ModTime

func IsStatusClientError added in v1.0.26

func IsStatusClientError(status int) bool

IsStatusClientError check status is client side error (400-499)

func IsStatusServerError added in v1.0.26

func IsStatusServerError(status int) bool

IsStatusServerError check status is server side error (500-599)

func NewHeaderWriter added in v1.0.12

func NewHeaderWriter(w http.ResponseWriter, key, value string) http.ResponseWriter

NewHeaderWriter create a http.ResponseWriter to append on WriteHeader(statusCode int). if statusCode != 200, header will not append. a existing header will not be overwriten.

func NewHeadersWriter added in v1.0.12

func NewHeadersWriter(w http.ResponseWriter, h map[string]string) http.ResponseWriter

NewHeadersWriter create a http.ResponseWriter to append on WriteHeader(statusCode int). if statusCode != 200, header will not append. a existing header will not be overwriten.

func NoRedirect added in v1.0.12

func NoRedirect(req *http.Request, via []*http.Request) error

NoRedirect just return http.ErrUseLastResponse. set http.Client.CheckRedirect to disable auto redirect. Example: http.Client{ChecRedirect: httpx.NoRedirect }

func ParseList

func ParseList(value string) []string

ParseList parses a comma-separated list of values as described by RFC 2068 and returns list elements.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go which was ported from urllib2.parse_http_list, from the Python standard library.

func ParsePairs

func ParsePairs(value string) map[string]string

ParsePairs extracts key/value pairs from a comma-separated list of values as described by RFC 2068 and returns a map[key]value. The resulting values are unquoted. If a list element doesn't contain a "=", the key is the element itself and the value is an empty string.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go

func ReadMultipartFile added in v1.0.13

func ReadMultipartFile(file *multipart.FileHeader) ([]byte, error)

ReadMultipartFile read multipart file and return it's content []byte.

func SaveMultipartFile added in v1.0.13

func SaveMultipartFile(file *multipart.FileHeader, dst string) error

SaveMultipartFile save multipart file to the specific local file 'dst'.

func SetAttachmentHeader added in v1.0.10

func SetAttachmentHeader(header http.Header, filename string)

SetAttachmentHeader set header Content-Disposition: attachment; filename=...

func URLReplace

func URLReplace(src, des string, hh http.Handler) http.Handler

URLReplace returns a handler that serves HTTP requests by replacing the request URL's Path (and RawPath if set) (use strings.Replace(path, src, des) and invoking the handler hh.

Types

type MultipartWriter

type MultipartWriter struct {
	*multipart.Writer
}

func NewMultipartWriter

func NewMultipartWriter(w io.Writer) *MultipartWriter

func (*MultipartWriter) CreateFormFile

func (mw *MultipartWriter) CreateFormFile(fieldname, filename string) (io.Writer, error)

func (*MultipartWriter) WriteFields

func (mw *MultipartWriter) WriteFields(fields url.Values) error

WriteFields calls WriteField and then writes the given fields values.

func (*MultipartWriter) WriteFile

func (mw *MultipartWriter) WriteFile(fieldname, filename string) error

WriteFile calls CreateFormFile and then writes the given file.

func (*MultipartWriter) WriteFileData

func (mw *MultipartWriter) WriteFileData(fieldname, filename string, data []byte) error

WriteFileData calls CreateFormFile and then writes the given file data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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