httpx

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 15 Imported by: 0

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 ContextWithStatusCode

func ContextWithStatusCode(ctx context.Context, statusCode int) context.Context

func MaybeWriteHeader

func MaybeWriteHeader(ctx context.Context, w io.Writer, contentType string, param map[string]string)

func Metadata

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

func StatusCodeFromContext

func StatusCodeFromContext(ctx context.Context) int

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

type Encode func(ctx context.Context, 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

type Method struct {
}

type MethodConnect

type MethodConnect struct{}

func (MethodConnect) Method

func (MethodConnect) Method() string

type MethodDelete

type MethodDelete struct{}

func (MethodDelete) Method

func (MethodDelete) Method() string

type MethodGet

type MethodGet struct{}

func (MethodGet) Method

func (MethodGet) Method() string

type MethodHead

type MethodHead struct{}

func (MethodHead) Method

func (MethodHead) Method() string

type MethodOptions

type MethodOptions struct{}

func (MethodOptions) Method

func (MethodOptions) Method() string

type MethodPatch

type MethodPatch struct{}

func (MethodPatch) Method

func (MethodPatch) Method() string

type MethodPost

type MethodPost struct{}

func (MethodPost) Method

func (MethodPost) Method() string

type MethodPut

type MethodPut struct{}

func (MethodPut) Method

func (MethodPut) Method() string

type MethodTrace

type MethodTrace struct{}

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 RequestInfo

type RequestInfo interface {
	Context() context.Context
	Values(in string, name string) []string
	Header() http.Header
	Body() io.ReadCloser
}

func NewRequestInfo

func NewRequestInfo(r *http.Request) RequestInfo

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

func (response *Response) Error() string

func (*Response) Unwrap

func (response *Response) Unwrap() error

func (*Response) WriteTo

func (response *Response) WriteTo(
	rw http.ResponseWriter,
	r *http.Request,
	resolveEncodeTo func(response *Response) (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

func WithSchema(s interface{}) ResponseWrapper

func WithStatusCode

func WithStatusCode(statusCode int) ResponseWrapper

type ResponseWriterError

type ResponseWriterError interface {
	WriteError(err error) (int, error)
}

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

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
	EncodeTo(w io.Writer, v interface{}) (mediaType string, err error)
	// decode from reader
	DecodeFrom(r io.Reader, v interface{}, headers ...textproto.MIMEHeader) error

	// Content-Type
	String() string
}

type Upgrader

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

type WithFromRequestInfo

type WithFromRequestInfo interface {
	FromRequestInfo(ri RequestInfo) error
}

type WithHeader

type WithHeader interface {
	Header() http.Header
}

Directories

Path Synopsis
__codegen__

Jump to

Keyboard shortcuts

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