http

package
v1.8.18 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyBytes

func BodyBytes(ctx context.Context, response *http.Response) ([]byte, error)

func Fetch

func Fetch[T interface{}](ctx context.Context, url, method string, payload interface{}, options ...FetchOptions) (T, error)

func FetchData

func FetchData(ctx context.Context, apiURL, method, stage string, headers *http.Header, responseType string) (string, error)

func FetchRaw

func FetchRaw(ctx context.Context, uri, method string, payload interface{}, options ...FetchOptions) (*http.Response, error)

func GetPublicIP added in v1.8.10

func GetPublicIP(proxy *Proxy) (string, error)

GetPublicIP returns the service's public-facing IP address by querying external IP detection services This is useful when the service is behind NAT and you need the internet-visible IP address

func JsonBody

func JsonBody[T interface{}](ctx context.Context, response *http.Response) (T, error)

func TextBody

func TextBody(ctx context.Context, response *http.Response) (string, error)

Types

type Client added in v1.2.0

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

Client is a custom HTTP client that can extract proxy information

func NewClient added in v1.2.0

func NewClient(timeout time.Duration, tlsConfig *tls.Config) *Client

NewClient creates a new custom HTTP client

func NewClientWithCookieJar added in v1.2.0

func NewClientWithCookieJar(timeout time.Duration, tlsConfig *tls.Config, cookieJar *cookiejar.Jar) *Client

NewClientWithCookieJar creates a new custom HTTP client with cookie jar

func (*Client) Do added in v1.2.0

func (c *Client) Do(ctx context.Context, opts RequestOptions) (*Response, error)

Do performs an HTTP request and returns the response with optional proxy IP

type FetchOptions

type FetchOptions struct {
	Headers        *http.Header
	Cookies        *[]http.Cookie
	Proxy          *Proxy
	ShowCurl       bool
	RawBody        bool
	CookieJar      *cookiejar.Jar
	ReturnResponse bool
	Timeout        time.Duration
}

type HttpxResponse added in v1.2.0

type HttpxResponse struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	ProxyIP    string // X-Proxy-IP header from CONNECT response, empty if no proxy used
}

HttpxResponse represents the response from an HTTP request

func GetRequest added in v1.2.0

func GetRequest(ctx context.Context, url string, headers map[string]string, proxyURL string, timeout time.Duration) (*HttpxResponse, error)

GetRequest performs a GET request and returns an HttpxResponse

func GetRequestWithCookieJar added in v1.2.0

func GetRequestWithCookieJar(ctx context.Context, url string, headers map[string]string, proxyURL string, timeout time.Duration, cookieJar *cookiejar.Jar) (*HttpxResponse, error)

GetRequestWithCookieJar performs a GET request with cookie jar support and returns an HttpxResponse

func PostRequest added in v1.2.0

func PostRequest(ctx context.Context, url string, body []byte, headers map[string]string, proxyURL string, timeout time.Duration) (*HttpxResponse, error)

PostRequest performs a POST request and returns an HttpxResponse

func PostRequestWithCookieJar added in v1.2.0

func PostRequestWithCookieJar(ctx context.Context, url string, body []byte, headers map[string]string, proxyURL string, timeout time.Duration, cookieJar *cookiejar.Jar) (*HttpxResponse, error)

PostRequestWithCookieJar performs a POST request with cookie jar support and returns an HttpxResponse

func Request added in v1.2.0

func Request(ctx context.Context, method, url string, body []byte, headers map[string]string, proxyURL string, timeout time.Duration) (*HttpxResponse, error)

Request performs an HTTP request and returns an HttpxResponse

func RequestWithCookieJar added in v1.2.0

func RequestWithCookieJar(ctx context.Context, method, url string, body []byte, headers map[string]string, proxyURL string, timeout time.Duration, cookieJar *cookiejar.Jar) (*HttpxResponse, error)

RequestWithCookieJar performs an HTTP request with cookie jar support and returns an HttpxResponse

type Proxy

type Proxy struct {
	Host         string
	Port         string
	Username     string
	Password     string
	AssignedIp   string
	AssignedPort string
}

type RequestOptions added in v1.2.0

type RequestOptions struct {
	Method    string
	URL       string
	Body      io.Reader
	Headers   map[string]string
	ProxyURL  string
	Timeout   time.Duration
	TLSConfig *tls.Config
	CookieJar *cookiejar.Jar
}

RequestOptions contains options for making HTTP requests

type Response added in v1.2.0

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	ProxyIP    string // X-Proxy-IP header from CONNECT response, empty if no proxy used
}

Response represents the response from an HTTP request with optional proxy information

Jump to

Keyboard shortcuts

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