httpx

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 RegexpReplace added in v1.2.3

func RegexpReplace(expr, repl string, hh http.Handler) http.Handler

RegexpReplace returns a handler that serves HTTP requests by replacing the request URL's Path (and RawPath if set) (use Regexp.MustCompile(expr).ReplaceAllString(path, rep) and invoking the handler hh.

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(hh http.Header, filename string)

SetAttachmentHeader set header Content-Disposition: attachment; filename=... and Content-Type: mime.TypeByExtension(filename)

func StringReplace added in v1.2.3

func StringReplace(src, rep string, hh http.Handler) http.Handler

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

func StripPrefix added in v1.2.3

func StripPrefix(prefix string, h http.Handler) http.Handler

StripPrefix returns a handler that serves HTTP requests by removing the given prefix from the request URL's Path (and RawPath if set) and invoking the handler h. StripPrefix handles a request for a path that doesn't begin with prefix by replying with an HTTP 404 not found error. The prefix must match exactly: if the prefix in the request contains escaped characters the reply is also an HTTP 404 not found error.

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