httpclient

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: BSD-3-Clause Imports: 35 Imported by: 2

Documentation

Overview

Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	TraceConnections = TraceLevel(1 << iota)
	TraceRequestHeaders
	TraceDNS
	TraceTLS
	TraceHTTP1XX
	TraceRequestBody
	TraceResponseStatus
	TraceResponseHeaders
	TraceRedirects

	// TraceOff causes all tracing to be switched off
	TraceOff TraceLevel = 0

	// TraceOn enables tracing of when connections are made and header
	TraceOn = TraceRequestHeaders | TraceResponseStatus | TraceResponseHeaders

	// TraceVerbose enables tracing of DNS, TLS, HTTP 1xx responses
	TraceVerbose = TraceOn | TraceConnections | TraceDNS | TraceTLS | TraceHTTP1XX | TraceRedirects
	TraceDebug   = TraceVerbose | TraceRequestBody
)

Trace level components, which enumerates the various parts of the roundtrip to trace

Variables

View Source
var (
	Authenticators = &provider.Registry{
		Name: "authenticators",
		Providers: provider.Map{
			"basic": {},
			"none":  {},
		},
	}
)

Functions

func ContextValue

func ContextValue(c *Client) cli.Action

func ExpandHeader

func ExpandHeader(h http.Header) expr.Expander

func ExpandResponse

func ExpandResponse(r *Response) expr.Expander

func FetchAndPrint

func FetchAndPrint() cli.Action

func FlagsAndArgs

func FlagsAndArgs() cli.Action

func ListAuthenticators

func ListAuthenticators() cli.Action

ListAuthenticators provides an action which will list the providers

func ListCiphers

func ListCiphers() cli.Action

func ListCurves

func ListCurves() cli.Action

func ListInterfaces

func ListInterfaces() cli.Action

func NewIntegrityDownloadMiddleware

func NewIntegrityDownloadMiddleware(i Integrity) func(Downloader) Downloader

func PromptForCredentials

func PromptForCredentials() cli.Action

PromptForCredentials will display prompts for user and/or password credentials if authentication is required.

func SetAuth

func SetAuth(v ...*provider.Value) cli.Action

func SetBaseURL

func SetBaseURL(name ...*URLValue) cli.Action

func SetBasicAuth

func SetBasicAuth() cli.Action

func SetBindAddress

func SetBindAddress(v ...string) cli.Action

func SetBody

func SetBody(s ...string) cli.Action

func SetBodyContent

func SetBodyContent(s ...*ContentType) cli.Action

func SetCACertFile

func SetCACertFile(path ...string) cli.Action

func SetCACertPath

func SetCACertPath(path ...string) cli.Action

func SetCiphers

func SetCiphers(v ...*CipherSuites) cli.Action

func SetClientCertFile

func SetClientCertFile(path ...string) cli.Action

func SetCurves

func SetCurves(v ...*CurveIDs) cli.Action

func SetDNSInterface

func SetDNSInterface(s ...string) cli.Action

func SetDialKeepAlive

func SetDialKeepAlive(v ...time.Duration) cli.Action

func SetDialTimeout

func SetDialTimeout(s ...time.Duration) cli.Action

func SetDisableDialKeepAlive

func SetDisableDialKeepAlive() cli.Action

func SetDownload

func SetDownload() cli.Action

func SetFailFast

func SetFailFast(i ...bool) cli.Action

func SetFillValue

func SetFillValue(s ...*cli.NameValue) cli.Action

func SetFollowRedirects

func SetFollowRedirects(s ...bool) cli.Action

func SetHeader

func SetHeader(s ...*HeaderValue) cli.Action

func SetIncludeResponseHeaders

func SetIncludeResponseHeaders(s ...bool) cli.Action

func SetInsecureSkipVerify

func SetInsecureSkipVerify(v ...bool) cli.Action

func SetIntegrity

func SetIntegrity(i ...Integrity) cli.Action

func SetInterface

func SetInterface(v ...string) cli.Action

func SetJSON

func SetJSON() cli.Action

func SetJSONContent

func SetJSONContent() cli.Action

func SetKeyFile

func SetKeyFile(path ...string) cli.Action

func SetMethod

func SetMethod(s ...string) cli.Action

func SetNextProtos

func SetNextProtos(s ...[]string) cli.Action

func SetNoOutput

func SetNoOutput(b ...bool) cli.Action

func SetOutputFile

func SetOutputFile(f ...string) cli.Action

func SetPreferGo

func SetPreferGo() cli.Action

func SetQueryString

func SetQueryString(s ...*cli.NameValue) cli.Action

func SetRequestID

func SetRequestID(s ...string) cli.Action

func SetServerName

func SetServerName(s ...string) cli.Action

func SetStrictErrorsDNS

func SetStrictErrorsDNS() cli.Action

func SetStripComponents

func SetStripComponents(i ...int) cli.Action

func SetTLSv1

func SetTLSv1() cli.Action

func SetTLSv1_0

func SetTLSv1_0() cli.Action

func SetTLSv1_1

func SetTLSv1_1() cli.Action

func SetTLSv1_2

func SetTLSv1_2() cli.Action

func SetTLSv1_3

func SetTLSv1_3() cli.Action

func SetTime

func SetTime(s ...*cli.File) cli.Action

func SetTraceLevel

func SetTraceLevel(s ...*TraceLevel) cli.Action

SetTraceLevel provides the action for a flag which sets the trace level corresponding to the flag's value.

func SetURITemplateVar

func SetURITemplateVar(v ...*uritemplates.Var) cli.Action

func SetURITemplateVars

func SetURITemplateVars(v ...uritemplates.Vars) cli.Action

func SetURLValue

func SetURLValue(i ...*URLValue) cli.Action

func SetUser

func SetUser(s ...*UserInfo) cli.Action

func SetUserAgent

func SetUserAgent(s ...string) cli.Action

func SetVerbose

func SetVerbose() cli.Action

func SetWriteErr

func SetWriteErr(w ...Expr) cli.Action

func SetWriteOut

func SetWriteOut(w ...Expr) cli.Action

func SourceAnnotation

func SourceAnnotation() (string, string)

SourceAnnotation gets the name and value of the annotation added to the Data of all flags that are initialized from this package

Types

type AuthMode

type AuthMode int

AuthMode enumerates common authenticators

const (
	NoAuth AuthMode = iota
	BasicAuth
)

Built-in authentication modes

func (AuthMode) Authenticate

func (m AuthMode) Authenticate(r *http.Request, ui *UserInfo) error

func (AuthMode) MarshalText

func (m AuthMode) MarshalText() ([]byte, error)

MarshalText provides the textual representation

func (AuthMode) RequiresUserInfo

func (m AuthMode) RequiresUserInfo() bool

func (*AuthMode) Set

func (m *AuthMode) Set(arg string) error

func (AuthMode) String

func (m AuthMode) String() string

func (*AuthMode) Synopsis

func (*AuthMode) Synopsis() string

func (*AuthMode) UnmarshalText

func (m *AuthMode) UnmarshalText(b []byte) error

UnmarshalText converts the textual representation

type Authenticator

type Authenticator interface {
	RequiresUserInfo() bool
	Authenticate(r *http.Request, u *UserInfo) error
}

func NewAuthenticator

func NewAuthenticator(name string, opts map[string]string) (Authenticator, error)

func WithPromptForCredentials

func WithPromptForCredentials(auth Authenticator) Authenticator

type CipherSuites

type CipherSuites []uint16

func (*CipherSuites) Set

func (c *CipherSuites) Set(arg string) error

func (*CipherSuites) String

func (c *CipherSuites) String() string

func (*CipherSuites) Synopsis

func (c *CipherSuites) Synopsis() string

type Client

type Client struct {
	Transport              http.RoundTripper
	CheckRedirect          func(*http.Request, []*http.Request) error
	Request                *http.Request
	IncludeResponseHeaders bool
	InterfaceResolver      InterfaceResolver
	BodyContent            Content
	UserInfo               *UserInfo
	LocationResolver       LocationResolver

	// FailFast causes no response output in the case of a failure
	FailFast bool
	// contains filtered or unexported fields
}

Client provides an HTTP client that can be accessed from commands, flags, and args within Joe applications. When you register the Client within a Uses pipeline, it also registers flags, templates, and other handlers to enable its configuration from the command line. The simplest action to use is FetchAndPrint(), which executes the request(s) and prints (or downloads) the results:

&cli.App{
   Name: "gocurl",
   Uses: &httpclient.New(),
   Action: httpclient.FetchAndPrint(),
}

This simple app has numerous flags and its simplest invocation could be something like

gocurl https://example.com/

The cmd/wig package provides wig, which is a command line utility very similar to this.

If you only want to add the Client to the context (typically in advanced scenarios where you are deeply customizing the behavior), you only use the action httpclient.ContextValue() with the client you want to add instead of add the client to the pipeline directly.

func FromContext

func FromContext(c context.Context) *Client

FromContext obtains the client stored in the context

func New

func New(options ...Option) *Client

func (*Client) AddMiddleware

func (c *Client) AddMiddleware(m Middleware)

func (*Client) AddTransportMiddleware

func (c *Client) AddTransportMiddleware(m TransportMiddleware)

func (*Client) Authenticator

func (c *Client) Authenticator() Authenticator

func (*Client) DNSDialer

func (c *Client) DNSDialer() *net.Dialer

func (*Client) Dialer

func (c *Client) Dialer() *net.Dialer

func (*Client) Do

func (c *Client) Do(ctx context.Context) ([]*Response, error)

func (*Client) Execute

func (c *Client) Execute(ctx context.Context) error

func (*Client) SetAuth

func (c *Client) SetAuth(auth Authenticator) error

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(u *URLValue) error

func (*Client) SetBindAddress

func (c *Client) SetBindAddress(value string) error

func (*Client) SetBody

func (c *Client) SetBody(body string) error

func (*Client) SetBodyContent

func (c *Client) SetBodyContent(bodyContent Content) error

func (*Client) SetCACertFile

func (c *Client) SetCACertFile(path string) error

func (*Client) SetCACertPath

func (c *Client) SetCACertPath(path string) error

func (*Client) SetCiphers

func (c *Client) SetCiphers(ids *CipherSuites) error

func (*Client) SetClientCertFile

func (c *Client) SetClientCertFile(path string) error

func (*Client) SetCurves

func (c *Client) SetCurves(ids *CurveIDs) error

func (*Client) SetDNSInterface

func (c *Client) SetDNSInterface(value string) error

func (*Client) SetDialKeepAlive

func (c *Client) SetDialKeepAlive(v time.Duration) error

func (*Client) SetDialTimeout

func (c *Client) SetDialTimeout(v time.Duration) error

func (*Client) SetDisableDialKeepAlive

func (c *Client) SetDisableDialKeepAlive(v bool) error

func (*Client) SetDownloadFile

func (c *Client) SetDownloadFile(v Downloader) error

func (*Client) SetFailFast

func (c *Client) SetFailFast(v bool) error

func (*Client) SetFillValue

func (c *Client) SetFillValue(v *cli.NameValue) error

func (*Client) SetFollowRedirects

func (c *Client) SetFollowRedirects(value bool) error

func (*Client) SetHeader

func (c *Client) SetHeader(n *HeaderValue) error

func (*Client) SetIncludeResponseHeaders

func (c *Client) SetIncludeResponseHeaders(v bool) error

func (*Client) SetInsecureSkipVerify

func (c *Client) SetInsecureSkipVerify(v bool) error

func (*Client) SetIntegrity

func (c *Client) SetIntegrity(i Integrity) error

func (*Client) SetInterface

func (c *Client) SetInterface(value string) error

func (*Client) SetKeyFile

func (c *Client) SetKeyFile(path string) error

func (*Client) SetMethod

func (c *Client) SetMethod(s string) error

func (*Client) SetNextProtos

func (c *Client) SetNextProtos(s []string) error

func (*Client) SetNoOutput

func (c *Client) SetNoOutput(b bool) error

func (*Client) SetOutputFile

func (c *Client) SetOutputFile(f string) error

func (*Client) SetPreferGoDialer

func (c *Client) SetPreferGoDialer(v bool) error

func (*Client) SetQueryString

func (c *Client) SetQueryString(n *cli.NameValue) error

func (*Client) SetRequestID

func (c *Client) SetRequestID(s string) error

func (*Client) SetServerName

func (c *Client) SetServerName(s string) error

func (*Client) SetStrictErrorsDNS

func (c *Client) SetStrictErrorsDNS(v bool) error

func (*Client) SetStripComponents

func (c *Client) SetStripComponents(count int) error

func (*Client) SetTraceLevel

func (c *Client) SetTraceLevel(v TraceLevel) error

func (*Client) SetURITemplateVar

func (c *Client) SetURITemplateVar(v *uritemplates.Var) error

func (*Client) SetURITemplateVars

func (c *Client) SetURITemplateVars(v uritemplates.Vars) error

func (*Client) SetURL

func (c *Client) SetURL(u *url.URL) error

func (*Client) SetURLValue

func (c *Client) SetURLValue(u *URLValue) error

func (*Client) SetUser

func (c *Client) SetUser(user *UserInfo) error

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(value string) error

func (*Client) SetWriteErr

func (c *Client) SetWriteErr(w Expr) error

func (*Client) SetWriteOut

func (c *Client) SetWriteOut(w Expr) error

func (*Client) TLSConfig

func (c *Client) TLSConfig() *tls.Config

func (*Client) UseAuthMiddleware

func (c *Client) UseAuthMiddleware(fn func(Authenticator) Authenticator)

func (*Client) UseDownloadMiddleware

func (c *Client) UseDownloadMiddleware(fn func(Downloader) Downloader)

type Content

type Content interface {
	Read() io.Reader
	Query() (url.Values, error)
	ContentType() string
	Set(name, value string) error
	SetFile(name, file io.Reader) error
}

Content implements the logic to build the body content of a request or to produce the query string if else.

func NewContent

func NewContent(ct ContentType) Content

type ContentType

type ContentType int
const (
	// ContentTypeFormData is the content type associated with either URL-encoded or multipart form data
	// depending upon whether files are set
	ContentTypeFormData ContentType = iota

	// ContentTypeRaw is the content type associated with raw content
	ContentTypeRaw ContentType = iota

	// ContentTypeURLEncodedFormData is URL encoding form data body content
	ContentTypeURLEncodedFormData

	// ContentTypeMultipartFormData is multi-part form data body content
	ContentTypeMultipartFormData

	// ContentTypeJSON is JSON data body content
	ContentTypeJSON
)

func (ContentType) MarshalText

func (c ContentType) MarshalText() ([]byte, error)

func (*ContentType) Set

func (c *ContentType) Set(arg string) error

func (ContentType) String

func (c ContentType) String() string

func (ContentType) Synopsis

func (ContentType) Synopsis() string

func (*ContentType) UnmarshalText

func (c *ContentType) UnmarshalText(b []byte) error

type CurveIDs

type CurveIDs []tls.CurveID

func (*CurveIDs) Set

func (c *CurveIDs) Set(arg string) error

func (*CurveIDs) String

func (c *CurveIDs) String() string

func (*CurveIDs) Synopsis

func (c *CurveIDs) Synopsis() string

type DownloadMode

type DownloadMode int

DownloadMode enumerates common download methods. It implements Downloader

const (
	PreserveRequestFile DownloadMode = iota
	PreserveRequestPath
)

Download modes. PreserveRequestFile uses the remote file name. PreserveRequestPath uses the remote file path.

func (DownloadMode) FileName

func (d DownloadMode) FileName(r *Response) string

func (DownloadMode) OpenDownload

func (d DownloadMode) OpenDownload(ctx context.Context, resp *Response) (io.WriteCloser, error)

func (DownloadMode) WithStripComponents

func (d DownloadMode) WithStripComponents(count int) Downloader

WithStripComponents returns a Downloader which strips the specified number of leading path elements from the resulting file name. This only pertains to PreserveRequestPath.

type Downloader

type Downloader interface {
	// OpenDownload saves the download from the response.  This method can be
	// called multiple times if multiple URLs were requested.
	OpenDownload(context.Context, *Response) (io.WriteCloser, error)
}

Downloader provides the behavior for downloading a response

func NewDownloaderTo

func NewDownloaderTo(w io.Writer) Downloader

NewDownloaderTo implements a basic downloader that copies to a writer

func NewFileDownloader

func NewFileDownloader(f string, fileSystem fs.FS) Downloader

NewFileDownloader implements a downloader that copies to a file system. The f argument specifies the name of the file to copy to. It may contain "write out" variables that are expanded. By default, a suffix is added for successive downloads of the same file name.

func NewIntegrityDownloader

func NewIntegrityDownloader(i Integrity, d Downloader) Downloader

type Expr

type Expr string

Expr provides the expression used within the "write out" flag

func (Expr) Compile

func (e Expr) Compile() *expr.Pattern

func (*Expr) UnmarshalText

func (e *Expr) UnmarshalText(b []byte) error

type FormDataContent

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

func (*FormDataContent) ContentType

func (c *FormDataContent) ContentType() string

func (*FormDataContent) Query

func (c *FormDataContent) Query() (url.Values, error)

func (*FormDataContent) Read

func (c *FormDataContent) Read() io.Reader

func (*FormDataContent) Set

func (c *FormDataContent) Set(name, value string) error

func (*FormDataContent) SetFile

func (c *FormDataContent) SetFile(name, file io.Reader) error

type HeaderValue

type HeaderValue struct {
	// Name in the header
	Name string
	// Value in the header
	Value string
}

HeaderValue provides an instance of a value in a header

func (*HeaderValue) Copy

func (v *HeaderValue) Copy() *HeaderValue

func (*HeaderValue) NewCounter

func (v *HeaderValue) NewCounter() cli.ArgCounter

func (*HeaderValue) Reset

func (v *HeaderValue) Reset()

func (*HeaderValue) Set

func (v *HeaderValue) Set(arg string) error

func (*HeaderValue) String

func (v *HeaderValue) String() string

String obtains the string representation of the name-value pair

type Integrity

type Integrity struct {
	Hash   crypto.Hash
	Digest []byte
}

func ParseIntegrity

func ParseIntegrity(s string) (Integrity, error)

func (*Integrity) UnmarshalText

func (i *Integrity) UnmarshalText(b []byte) error

type InterfaceResolver

type InterfaceResolver interface {
	// Resolve converts a location, typically an IP address
	// or adapter name, into a TCP address
	Resolve(string) (*net.TCPAddr, error)
}

InterfaceResolver resolves the network interface to use for connections

type JSONContent

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

func (*JSONContent) ContentType

func (c *JSONContent) ContentType() string

func (*JSONContent) Query

func (c *JSONContent) Query() (url.Values, error)

func (*JSONContent) Read

func (c *JSONContent) Read() io.Reader

func (*JSONContent) Set

func (c *JSONContent) Set(name, value string) error

func (*JSONContent) SetFile

func (c *JSONContent) SetFile(name, file io.Reader) error

type Location

type Location interface {
	// URL derives a context that should be used for the client request for the
	// given URL, the URL itself to use.  An error can be returned, usually if the
	// input context ctx is lacking a required service.
	URL(ctx context.Context) (context.Context, *url.URL, error)
}

Location specifies the request location. A location comprises a URL that will be requested by the HTTP client and a context function that helps initialize any context values that might be needed such as by middleware. This is an indirection typically used to provide behavior dependent upon the request URL. If Location also implements client Middleware, it will be the first middleware function used when the client fetches the request

func URLLocation

func URLLocation(u *url.URL) Location

URLLocation provides a basic implementation of Location for a URL. It isn't dependent upon and makes no modifications to the context

type LocationResolver

type LocationResolver interface {
	// Add a location to be resolved.  This is typically in the syntax
	// of either a URL or a URI template.
	Add(location string) error
	// Add a variable that can be applied to templates.
	AddVar(v *uritemplates.Var) error
	// Set the base URL used for resolving relative URLs.
	SetBase(base *url.URL) error
	// Resolve the list of locations. Each location is represented
	// as a URL and the context the client should use to issue the
	// request.
	Resolve(context.Context) ([]Location, error)
}

LocationResolver provides the logic of the how the URL to request is resolved.

func NewDefaultLocationResolver

func NewDefaultLocationResolver() LocationResolver

NewDefaultLocationResolver provides a location resolver that supports relative addressing and URI templates

type Middleware

type Middleware interface {
	Handle(req *http.Request, next func(*http.Request) error) error
}

Middleware provides logic that intercepts and processes each request. The next function should be called to continue the middleware pipeline.

func ComposeMiddleware

func ComposeMiddleware(mw ...Middleware) Middleware

ComposeMiddleware creates middleware from a list

func NewRequestIDMiddleware

func NewRequestIDMiddleware(v ...any) Middleware

NewRequestIDMiddleware generates a request ID for each request using the X-Request-ID header

func WithHeader

func WithHeader(name string, value any) Middleware

WithHeader sets the specified header. The value may be:

  • string
  • []string
  • func()string
  • func()[]string.
  • func(*http.Request)(string, error).
  • func(*http.Request)([]string, error).

Other types using their default string format.

func WithHeaders

func WithHeaders(headers http.Header) Middleware

WithHeaders sets the specified headers.

type MiddlewareFunc

type MiddlewareFunc func(req *http.Request) error

MiddlewareFunc implements Middleware as a function which implements the solitary corresponding method of the interface and automatically delegates to the next middleware.

func (MiddlewareFunc) Handle

func (f MiddlewareFunc) Handle(req *http.Request, next func(*http.Request) error) error

type MultipartFormDataContent

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

func (*MultipartFormDataContent) ContentType

func (c *MultipartFormDataContent) ContentType() string

func (*MultipartFormDataContent) Query

func (c *MultipartFormDataContent) Query() (url.Values, error)

func (*MultipartFormDataContent) Read

func (c *MultipartFormDataContent) Read() io.Reader

func (*MultipartFormDataContent) Set

func (c *MultipartFormDataContent) Set(name, value string) error

func (*MultipartFormDataContent) SetFile

func (c *MultipartFormDataContent) SetFile(name, file io.Reader) error

type NameValue

type NameValue struct {
	Name  string
	Value string
}

type Option

type Option func(*Client)

Option is an option to configure the client

func WithDefaultUserAgent

func WithDefaultUserAgent(s string) Option

func WithLocationResolver

func WithLocationResolver(r LocationResolver) Option

func WithMiddleware

func WithMiddleware(m Middleware) Option

WithMiddleware adds a middleware function that will execute before the client request

func WithRequestID

func WithRequestID(v ...any) Option

WithRequestID provides middleware to the client that adds a header X-Request-ID to the request. The optional argument defines how to generate the ID. When specified, it must be one of these types:

  • string
  • func()string
  • func(context.Context)(string, error)

When unspecified, a cryptographically random string is generated for request IDs.

func WithTransport

func WithTransport(t http.RoundTripper) Option

WithTransport sets the default transport

func WithTransportMiddleware

func WithTransportMiddleware(m TransportMiddleware) Option

WithTransportMiddleware adds middleware to the transport

func (Option) Execute

func (o Option) Execute(c context.Context) error

type RawContent

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

func NewRawContent

func NewRawContent(data []byte) *RawContent

NewRawContent provides body content that is formed from raw data

func NewStringContent

func NewStringContent(data string) *RawContent

NewStringContent provides body content that is formed from a string

func (*RawContent) ContentType

func (c *RawContent) ContentType() string

func (*RawContent) Query

func (c *RawContent) Query() (url.Values, error)

func (*RawContent) Read

func (c *RawContent) Read() io.Reader

func (*RawContent) Set

func (c *RawContent) Set(_, _ string) error

func (*RawContent) SetFile

func (c *RawContent) SetFile(_, _ io.Reader) error

func (*RawContent) Write

func (c *RawContent) Write(d []byte) (int, error)

func (*RawContent) WriteString

func (c *RawContent) WriteString(d string) (int, error)

type Response

type Response struct {
	*http.Response
}

func Do

func Do(c *cli.Context) ([]*Response, error)

func (*Response) CopyHeadersTo

func (r *Response) CopyHeadersTo(w io.Writer) error

func (*Response) CopyTo

func (r *Response) CopyTo(w io.Writer) error

func (*Response) Success

func (r *Response) Success() bool

type RoundTripperFunc

type RoundTripperFunc func(req *http.Request) *http.Response

func (RoundTripperFunc) RoundTrip

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

type TraceLevel

type TraceLevel int

TraceLevel indicates the amount of client tracing to generate

func (*TraceLevel) Set

func (l *TraceLevel) Set(arg string) error

func (TraceLevel) String

func (l TraceLevel) String() string

type TraceLogger

type TraceLogger interface {
	ConnectDone(network, addr string, err error)
	ConnectStart(network, addr string)
	DNSDone(httptrace.DNSDoneInfo)
	DNSStart(httptrace.DNSStartInfo)
	GetConn(hostPort string)
	Got1xxResponse(code int, header textproto.MIMEHeader) error
	GotConn(httptrace.GotConnInfo)
	TLSHandshakeDone(tls.ConnectionState, error)
	TLSHandshakeStart()
	Wait100Continue()
	WroteHeaderField(key string, value []string)
	WroteRequest(httptrace.WroteRequestInfo)
	StartRequest(req *http.Request)
	ResponseDone(resp *http.Response, err error)
	Redirected(req *http.Request, via []*http.Request, err error)
}

TraceLogger provides delegates from ClientTrace

type TransportMiddleware

type TransportMiddleware func(context.Context, http.RoundTripper) http.RoundTripper

TransportMiddleware provides middleware to the roundtripper

type URLEncodedFormDataContent

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

func (*URLEncodedFormDataContent) ContentType

func (c *URLEncodedFormDataContent) ContentType() string

func (*URLEncodedFormDataContent) Query

func (c *URLEncodedFormDataContent) Query() (url.Values, error)

func (*URLEncodedFormDataContent) Read

func (c *URLEncodedFormDataContent) Read() io.Reader

func (*URLEncodedFormDataContent) Set

func (c *URLEncodedFormDataContent) Set(name, value string) error

func (*URLEncodedFormDataContent) SetFile

func (c *URLEncodedFormDataContent) SetFile(name, file io.Reader) error

type URLValue

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

URLValue provides ergonomics for entering URLs as values. When the text looks like a port (e.g. :8080), the URL is interpeted as localhost. When the text looks like a hostname, the prefix http:// is preprended.

func NewURLValue

func NewURLValue(loc string) *URLValue

NewURLValue creates a new URLValue from a string

func (*URLValue) Copy

func (u *URLValue) Copy() *URLValue

func (*URLValue) Reset

func (u *URLValue) Reset()

func (*URLValue) Set

func (u *URLValue) Set(arg string) error

func (*URLValue) String

func (u *URLValue) String() string

func (*URLValue) URITemplate

func (u *URLValue) URITemplate() (*uritemplates.URITemplate, error)

URITemplate interprets the value as a URI Template

func (*URLValue) URL

func (u *URLValue) URL() (*url.URL, error)

URL interprets the value as a URL

type UserInfo

type UserInfo struct {
	User        string
	Password    string
	HasPassword bool
}

UserInfo provides the username and password

func (*UserInfo) Set

func (u *UserInfo) Set(arg string) error

func (*UserInfo) String

func (u *UserInfo) String() string

func (*UserInfo) Synopsis

func (*UserInfo) Synopsis() string

type VirtualPath

type VirtualPath struct {
	// RequestPath identifies the request path prefix to match
	RequestPath string

	// PhysicalPath identifies the real path that contains the resource to be served
	PhysicalPath string

	// Options encapsulates options about the virtual path
	Options map[string]string
}

VirtualPath identifies the mapping between a request path and a real file system path

func ParseVirtualPath

func ParseVirtualPath(v string) (VirtualPath, error)

func (*VirtualPath) Copy

func (v *VirtualPath) Copy() *VirtualPath

func (*VirtualPath) NewCounter

func (v *VirtualPath) NewCounter() cli.ArgCounter

func (*VirtualPath) Reset

func (v *VirtualPath) Reset()

func (*VirtualPath) Set

func (v *VirtualPath) Set(arg string) error

func (VirtualPath) String

func (v VirtualPath) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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