httplib

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 22 Imported by: 133

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequestContextKey = RequestContextKeyStruct{}

Functions

func DialContextWithTimeout added in v1.25.0

func DialContextWithTimeout(timeout time.Duration) func(ctx context.Context, network, address string) (net.Conn, error)

func EncodeContentDispositionAttachment added in v1.26.0

func EncodeContentDispositionAttachment(filename string) string

func EncodeContentDispositionInline added in v1.26.0

func EncodeContentDispositionInline(filename string) string

func GuessCurrentAppURL added in v1.22.0

func GuessCurrentAppURL(ctx context.Context) string

GuessCurrentAppURL tries to guess the current full public URL (with sub-path) by http headers. It always has a '/' suffix, exactly the same as setting.AppURL TODO: should rename it to GuessCurrentPublicURL in the future

func GuessCurrentHostDomain added in v1.24.0

func GuessCurrentHostDomain(ctx context.Context) string

func GuessCurrentHostURL added in v1.22.1

func GuessCurrentHostURL(ctx context.Context) string

GuessCurrentHostURL tries to guess the current full host URL (no sub-path) by http headers, there is no trailing slash.

func IsCurrentGiteaSiteURL added in v1.22.0

func IsCurrentGiteaSiteURL(ctx context.Context, s string) bool

func IsRelativeURL added in v1.22.0

func IsRelativeURL(s string) bool

IsRelativeURL detects if a URL is relative (no scheme or host)

func MakeAbsoluteURL added in v1.22.0

func MakeAbsoluteURL(ctx context.Context, link string) string

MakeAbsoluteURL tries to make a link to an absolute public URL: * If link is empty, it returns the current public URL. * If link is absolute, it returns the link. * Otherwise, it returns the current host URL + link, the link itself should have correct sub-path (AppSubURL) if needed.

func ServeSetHeaders added in v1.20.0

func ServeSetHeaders(w http.ResponseWriter, opts ServeHeaderOptions)

ServeSetHeaders sets necessary content serve headers

func ServeUserContentByFile added in v1.26.0

func ServeUserContentByFile(r *http.Request, w http.ResponseWriter, file fs.File, opts ServeHeaderOptions)

func ServeUserContentByReader added in v1.26.0

func ServeUserContentByReader(r *http.Request, w http.ResponseWriter, size int64, reader io.Reader, opts ServeHeaderOptions)

Types

type ContentDispositionType added in v1.26.0

type ContentDispositionType string
const (
	ContentDispositionInline     ContentDispositionType = "inline"
	ContentDispositionAttachment ContentDispositionType = "attachment"
)

type GiteaSiteURL added in v1.24.0

type GiteaSiteURL struct {
	RoutePath   string
	OwnerName   string
	RepoName    string
	RepoSubPath string
}

func ParseGiteaSiteURL added in v1.24.0

func ParseGiteaSiteURL(ctx context.Context, s string) *GiteaSiteURL

type Request

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

func NewRequest added in v1.2.0

func NewRequest(url, method string) *Request

func (*Request) Body

func (r *Request) Body(data any) *Request

Body adds request raw body. It supports string, []byte and io.Reader as body.

func (*Request) GoString added in v1.20.0

func (r *Request) GoString() string

func (*Request) Header

func (r *Request) Header(key, value string) *Request

Header set header item string in request.

func (*Request) Param

func (r *Request) Param(key, value string) *Request

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) Response

func (r *Request) Response() (*http.Response, error)

Response executes request client and returns the response. Caller MUST close the response body if no error occurs.

func (*Request) SetContext added in v1.15.0

func (r *Request) SetContext(ctx context.Context) *Request

SetContext sets the request's Context

func (*Request) SetReadWriteTimeout added in v1.20.0

func (r *Request) SetReadWriteTimeout(readWriteTimeout time.Duration) *Request

func (*Request) SetTransport

func (r *Request) SetTransport(transport http.RoundTripper) *Request

SetTransport sets the request transport, if not set, will use httplib's default transport with environment proxy support ATTENTION: the http.Transport has a connection pool, so it should be reused as much as possible, do not create a lot of transports

type RequestContextKeyStruct added in v1.22.0

type RequestContextKeyStruct struct{}

type ServeHeaderOptions added in v1.20.0

type ServeHeaderOptions struct {
	ContentType   string // defaults to "application/octet-stream"
	ContentLength *int64

	Filename           string
	ContentDisposition ContentDispositionType

	CacheIsPublic bool
	CacheDuration time.Duration // defaults to 5 minutes
	LastModified  time.Time
}

Jump to

Keyboard shortcuts

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