httpx

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Examples

Constants

View Source
const (
	HeaderUserAgent          = "User-Agent"
	HeaderContentType        = "Content-Type"
	HeaderContentDisposition = "Content-Disposition"
	HeaderRequestID          = "X-Request-ID"
	HeaderForwardedFor       = "X-Forwarded-For"
	HeaderRealIP             = "X-Real-IP"
)
View Source
const (
	MIME_OCTET_STREAM      = "application/octet-stream"
	MIME_JSON              = "application/json"
	MIME_XML               = "application/xml"
	MIME_FORM_URLENCODED   = "application/x-www-form-urlencoded"
	MIME_MULTIPART_FORMDAT = "multipart/form-data"
	MIME_PROTOBUF          = "application/x-protobuf"
	MIME_MSGPACK           = "application/x-msgpack"
)

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

func ClientIPByHeaderForwardedFor

func ClientIPByHeaderForwardedFor(headerForwardedFor string) string

X-Forwarded-For: client, proxy1, proxy2 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

func ClientIPByHeaderRealIP

func ClientIPByHeaderRealIP(headerRealIP string) string

X-Forwarded-For: client, proxy1, proxy2 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

func Metadata

func Metadata(key string, values ...string) courier.Metadata

Types

type ApplicationOgg

type ApplicationOgg struct {
	bytes.Buffer
}
Example
m := NewApplicationOgg()

fmt.Println(m.ContentType())
Output:

application/ogg

func NewApplicationOgg

func NewApplicationOgg() *ApplicationOgg

func (ApplicationOgg) ContentType

func (ApplicationOgg) ContentType() string

type Attachment

type Attachment struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

func NewAttachment

func NewAttachment(filename string, contentType string) *Attachment
Example
a := NewAttachment("test.txt", MIME_JSON)
a.WriteString("{}")

fmt.Println(a.ContentType())
fmt.Println(a.Meta())
fmt.Println(a.String())
Output:

application/json
Content-Disposition=attachment%3B+filename%3Dtest.txt
{}
Example (WithDefaultContentType)
a := NewAttachment("test.txt", "")
a.WriteString("text")

fmt.Println(a.ContentType())
fmt.Println(a.Meta())
fmt.Println(a.String())
Output:

application/octet-stream
Content-Disposition=attachment%3B+filename%3Dtest.txt
text

func (*Attachment) ContentType

func (a *Attachment) ContentType() string

func (*Attachment) Meta

func (a *Attachment) Meta() courier.Metadata

type AudioMidi

type AudioMidi struct {
	bytes.Buffer
}
Example
m := NewAudioMidi()

fmt.Println(m.ContentType())
Output:

audio/midi

func NewAudioMidi

func NewAudioMidi() *AudioMidi

func (AudioMidi) ContentType

func (AudioMidi) ContentType() string

type AudioMp3

type AudioMp3 struct {
	bytes.Buffer
}
Example
m := NewAudioMp3()

fmt.Println(m.ContentType())
Output:

audio/mpeg

func NewAudioMp3

func NewAudioMp3() *AudioMp3

func (AudioMp3) ContentType

func (AudioMp3) ContentType() string

type AudioOgg

type AudioOgg struct {
	bytes.Buffer
}
Example
m := NewAudioOgg()

fmt.Println(m.ContentType())
Output:

audio/ogg

func NewAudioOgg

func NewAudioOgg() *AudioOgg

func (AudioOgg) ContentType

func (AudioOgg) ContentType() string

type AudioWave

type AudioWave struct {
	bytes.Buffer
}
Example
m := NewAudioWave()

fmt.Println(m.ContentType())
Output:

audio/wav

func NewAudioWave

func NewAudioWave() *AudioWave

func (AudioWave) ContentType

func (AudioWave) ContentType() string

type AudioWebm

type AudioWebm struct {
	bytes.Buffer
}
Example
m := NewAudioWebm()

fmt.Println(m.ContentType())
Output:

audio/webm

func NewAudioWebm

func NewAudioWebm() *AudioWebm

func (AudioWebm) ContentType

func (AudioWebm) ContentType() string

type CSS

type CSS struct {
	bytes.Buffer
}
Example
m := NewCSS()

fmt.Println(m.ContentType())
Output:

text/css

func NewCSS

func NewCSS() *CSS

func (CSS) ContentType

func (CSS) ContentType() string

type ContentTypeDescriber

type ContentTypeDescriber interface {
	ContentType() string
}

type CookiesDescriber

type CookiesDescriber interface {
	Cookies() []*http.Cookie
}

type Encode added in v1.14.11

type Encode func(w io.Writer, v interface{}) error

type HTML

type HTML struct {
	bytes.Buffer
}
Example
m := NewHTML()

fmt.Println(m.ContentType())
Output:

text/html

func NewHTML

func NewHTML() *HTML

func (HTML) ContentType

func (HTML) ContentType() string

type ImageBmp

type ImageBmp struct {
	bytes.Buffer
}
Example
m := NewImageBmp()

fmt.Println(m.ContentType())
Output:

image/bmp

func NewImageBmp

func NewImageBmp() *ImageBmp

func (ImageBmp) ContentType

func (ImageBmp) ContentType() string

type ImageGIF

type ImageGIF struct {
	bytes.Buffer
}
Example
m := NewImageGIF()

fmt.Println(m.ContentType())
Output:

image/gif

func NewImageGIF

func NewImageGIF() *ImageGIF

func (ImageGIF) ContentType

func (ImageGIF) ContentType() string

type ImageJPEG

type ImageJPEG struct {
	bytes.Buffer
}
Example
m := NewImageJPEG()

fmt.Println(m.ContentType())
Output:

image/jpeg

func NewImageJPEG

func NewImageJPEG() *ImageJPEG

func (ImageJPEG) ContentType

func (ImageJPEG) ContentType() string

type ImagePNG

type ImagePNG struct {
	bytes.Buffer
}
Example
m := NewImagePNG()

fmt.Println(m.ContentType())
Output:

image/png

func NewImagePNG

func NewImagePNG() *ImagePNG

func (ImagePNG) ContentType

func (ImagePNG) ContentType() string

type ImageSVG

type ImageSVG struct {
	bytes.Buffer
}
Example
m := NewImageSVG()

fmt.Println(m.ContentType())
Output:

image/svg+xml

func NewImageSVG

func NewImageSVG() *ImageSVG

func (ImageSVG) ContentType

func (ImageSVG) ContentType() string

type ImageWebp

type ImageWebp struct {
	bytes.Buffer
}
Example
m := NewImageWebp()

fmt.Println(m.ContentType())
Output:

image/webp

func NewImageWebp

func NewImageWebp() *ImageWebp

func (ImageWebp) ContentType

func (ImageWebp) ContentType() string

type Method added in v1.17.1

type Method struct {
}

type MethodConnect

type MethodConnect struct{}
Example
m := MethodConnect{}

fmt.Println(m.Method())
Output:

CONNECT

func (MethodConnect) Method

func (MethodConnect) Method() string

type MethodDelete

type MethodDelete struct{}
Example
m := MethodDelete{}

fmt.Println(m.Method())
Output:

DELETE

func (MethodDelete) Method

func (MethodDelete) Method() string

type MethodGet

type MethodGet struct{}
Example
m := MethodGet{}

fmt.Println(m.Method())
Output:

GET

func (MethodGet) Method

func (MethodGet) Method() string

type MethodHead

type MethodHead struct{}
Example
m := MethodHead{}

fmt.Println(m.Method())
Output:

HEAD

func (MethodHead) Method

func (MethodHead) Method() string

type MethodOptions

type MethodOptions struct{}
Example
m := MethodOptions{}

fmt.Println(m.Method())
Output:

OPTIONS

func (MethodOptions) Method

func (MethodOptions) Method() string

type MethodPatch

type MethodPatch struct{}
Example
m := MethodPatch{}

fmt.Println(m.Method())
Output:

PATCH

func (MethodPatch) Method

func (MethodPatch) Method() string

type MethodPost

type MethodPost struct{}
Example
m := MethodPost{}

fmt.Println(m.Method())
Output:

POST

func (MethodPost) Method

func (MethodPost) Method() string

type MethodPut

type MethodPut struct{}
Example
m := MethodPut{}

fmt.Println(m.Method())
Output:

PUT

func (MethodPut) Method

func (MethodPut) Method() string

type MethodTrace

type MethodTrace struct{}
Example
m := MethodTrace{}

fmt.Println(m.Method())
Output:

TRACE

func (MethodTrace) Method

func (MethodTrace) Method() string

type Plain

type Plain struct {
	bytes.Buffer
}
Example
m := NewPlain()

fmt.Println(m.ContentType())
Output:

text/plain

func NewPlain

func NewPlain() *Plain

func (Plain) ContentType

func (Plain) ContentType() string

type RedirectDescriber

type RedirectDescriber interface {
	StatusCodeDescriber
	Location() *url.URL
}

type Response

type Response struct {
	// value of Body
	Value       interface{}      `json:"-"`
	Metadata    courier.Metadata `json:"-"`
	Cookies     []*http.Cookie   `json:"-"`
	Location    *url.URL         `json:"-"`
	ContentType string           `json:"-"`
	StatusCode  int              `json:"-"`
}

func ResponseFrom

func ResponseFrom(v interface{}) *Response

func (*Response) Error added in v1.15.0

func (response *Response) Error() string

func (*Response) Unwrap added in v1.15.0

func (response *Response) Unwrap() error

func (*Response) WriteTo

func (response *Response) WriteTo(rw http.ResponseWriter, r *http.Request, resolveEncode func(response *Response) (string, Encode, error)) error

type ResponseWrapper

type ResponseWrapper func(v interface{}) *Response

func Compose

func Compose(responseWrappers ...ResponseWrapper) ResponseWrapper

func WithContentType

func WithContentType(contentType string) ResponseWrapper

func WithCookies

func WithCookies(cookies ...*http.Cookie) ResponseWrapper

func WithMetadata

func WithMetadata(metadatas ...courier.Metadata) ResponseWrapper

func WithSchema added in v1.12.0

func WithSchema(s interface{}) ResponseWrapper

func WithStatusCode

func WithStatusCode(statusCode int) ResponseWrapper

type StatusCodeDescriber

type StatusCodeDescriber interface {
	StatusCode() int
}

type StatusFound

type StatusFound struct {
	*Response
}
Example
m := RedirectWithStatusFound(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

302
/test

func RedirectWithStatusFound

func RedirectWithStatusFound(u *net_url.URL) *StatusFound

func (StatusFound) Location

func (r StatusFound) Location() *net_url.URL

func (StatusFound) StatusCode

func (StatusFound) StatusCode() int

type StatusMovedPermanently

type StatusMovedPermanently struct {
	*Response
}
Example
m := RedirectWithStatusMovedPermanently(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

301
/test

func RedirectWithStatusMovedPermanently

func RedirectWithStatusMovedPermanently(u *net_url.URL) *StatusMovedPermanently

func (StatusMovedPermanently) Location

func (r StatusMovedPermanently) Location() *net_url.URL

func (StatusMovedPermanently) StatusCode

func (StatusMovedPermanently) StatusCode() int

type StatusMultipleChoices

type StatusMultipleChoices struct {
	*Response
}
Example
m := RedirectWithStatusMultipleChoices(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

300
/test

func RedirectWithStatusMultipleChoices

func RedirectWithStatusMultipleChoices(u *net_url.URL) *StatusMultipleChoices

func (StatusMultipleChoices) Location

func (r StatusMultipleChoices) Location() *net_url.URL

func (StatusMultipleChoices) StatusCode

func (StatusMultipleChoices) StatusCode() int

type StatusNotModified

type StatusNotModified struct {
	*Response
}
Example
m := RedirectWithStatusNotModified(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

304
/test

func RedirectWithStatusNotModified

func RedirectWithStatusNotModified(u *net_url.URL) *StatusNotModified

func (StatusNotModified) Location

func (r StatusNotModified) Location() *net_url.URL

func (StatusNotModified) StatusCode

func (StatusNotModified) StatusCode() int

type StatusPermanentRedirect

type StatusPermanentRedirect struct {
	*Response
}
Example
m := RedirectWithStatusPermanentRedirect(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

308
/test

func RedirectWithStatusPermanentRedirect

func RedirectWithStatusPermanentRedirect(u *net_url.URL) *StatusPermanentRedirect

func (StatusPermanentRedirect) Location

func (r StatusPermanentRedirect) Location() *net_url.URL

func (StatusPermanentRedirect) StatusCode

func (StatusPermanentRedirect) StatusCode() int

type StatusSeeOther

type StatusSeeOther struct {
	*Response
}
Example
m := RedirectWithStatusSeeOther(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

303
/test

func RedirectWithStatusSeeOther

func RedirectWithStatusSeeOther(u *net_url.URL) *StatusSeeOther

func (StatusSeeOther) Location

func (r StatusSeeOther) Location() *net_url.URL

func (StatusSeeOther) StatusCode

func (StatusSeeOther) StatusCode() int

type StatusTemporaryRedirect

type StatusTemporaryRedirect struct {
	*Response
}
Example
m := RedirectWithStatusTemporaryRedirect(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

307
/test

func RedirectWithStatusTemporaryRedirect

func RedirectWithStatusTemporaryRedirect(u *net_url.URL) *StatusTemporaryRedirect

func (StatusTemporaryRedirect) Location

func (r StatusTemporaryRedirect) Location() *net_url.URL

func (StatusTemporaryRedirect) StatusCode

func (StatusTemporaryRedirect) StatusCode() int

type StatusUseProxy

type StatusUseProxy struct {
	*Response
}
Example
m := RedirectWithStatusUseProxy(&(net_url.URL{
	Path: "/test",
}))

fmt.Println(m.StatusCode())
fmt.Println(m.Location())
Output:

305
/test

func RedirectWithStatusUseProxy

func RedirectWithStatusUseProxy(u *net_url.URL) *StatusUseProxy

func (StatusUseProxy) Location

func (r StatusUseProxy) Location() *net_url.URL

func (StatusUseProxy) StatusCode

func (StatusUseProxy) StatusCode() int

type Transformer added in v1.14.11

type Transformer interface {
	// name or alias of transformer
	// prefer using some keyword about content-type
	Names() []string
	// create transformer new transformer instance by type
	// in this step will to check transformer is valid for type
	New(context.Context, typesutil.Type) (Transformer, error)

	// named by tag
	NamedByTag() string

	// encode to writer
	EncodeToWriter(w io.Writer, v interface{}) (mediaType string, err error)
	// decode from reader
	DecodeFromReader(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error

	// Content-Type
	String() string
}

type Upgrader added in v1.4.0

type Upgrader interface {
	Upgrade(w http.ResponseWriter, r *http.Request) error
}

type VideoOgg

type VideoOgg struct {
	bytes.Buffer
}
Example
m := NewVideoOgg()

fmt.Println(m.ContentType())
Output:

video/ogg

func NewVideoOgg

func NewVideoOgg() *VideoOgg

func (VideoOgg) ContentType

func (VideoOgg) ContentType() string

type VideoWebm

type VideoWebm struct {
	bytes.Buffer
}
Example
m := NewVideoWebm()

fmt.Println(m.ContentType())
Output:

video/webm

func NewVideoWebm

func NewVideoWebm() *VideoWebm

func (VideoWebm) ContentType

func (VideoWebm) ContentType() string

Directories

Path Synopsis
__codegen__

Jump to

Keyboard shortcuts

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