rawhttp

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

rawhttp

License Go Version Release Checks Go Reference

rawhttp is a Go package for making HTTP requests in a raw way.

License

license

Documentation

Index

Constants

View Source
const MaxResponseReadSizeDecompress = 10 * 1024 * 1024

Variables

View Source
var DefaultClient = Client{

	Options: DefaultOptions,
	// contains filtered or unexported fields
}

DefaultClient is the default HTTP client for doing raw requests

View Source
var DefaultOptions = &Options{
	Timeout:                30 * time.Second,
	FollowRedirects:        true,
	MaxRedirects:           10,
	AutomaticHostHeader:    true,
	AutomaticContentLength: true,
}

DefaultOptions is the default configuration options for the client

Functions

func AutomaticContentLength

func AutomaticContentLength(enable bool)

AutomaticContentLength performs automatic calculation of request content length.

func AutomaticHostHeader

func AutomaticHostHeader(enable bool)

AutomaticHostHeader sets Host header for requests automatically

func Do

func Do(req *http.Request) (*http.Response, error)

Do sends a http request and returns a response

func DoRaw

func DoRaw(method, url string, headers map[string][]string, body io.Reader) (*http.Response, error)

DoRaw does a raw request with some configuration

func DoRawWithOptions

func DoRawWithOptions(method, url string, headers map[string][]string, body io.Reader, options *Options) (*http.Response, error)

DoRawWithOptions does a raw request with some configuration

func DumpRequestRaw

func DumpRequestRaw(method, uri, uripath string, headers map[string][]string, body io.Reader, options *Options) ([]byte, error)

DumpRequestRaw to string

func Get

func Get(url string) (*http.Response, error)

Get makes a GET request to a given URL

func Post

func Post(url string, mimetype string, r io.Reader) (*http.Response, error)

Post makes a POST request to a given URL

func TlsHandshake added in v1.0.2

func TlsHandshake(conn net.Conn, addr string, timeout time.Duration) (net.Conn, error)

TlsHandshake tls handshake on a plain connection

Types

type Client

type Client struct {
	Options *Options
	Jar     *cookiejar.Jar
	// contains filtered or unexported fields
}

Client is a client for making raw http requests with go

func NewClient

func NewClient(options *Options) *Client

NewClient creates a new rawhttp client with provided options

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends a http request and returns a response

func (*Client) DoRaw

func (c *Client) DoRaw(method, url string, headers map[string][]string, body io.Reader) (*http.Response, error)

DoRaw does a raw request with some configuration

func (*Client) DoRawWithOptions

func (c *Client) DoRawWithOptions(method, url string, headers map[string][]string, body io.Reader, options *Options) (*http.Response, error)

DoRawWithOptions performs a raw request with additional options

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

Get makes a GET request to a given URL

func (*Client) Head

func (c *Client) Head(url string) (*http.Response, error)

Head makes a HEAD request to a given URL

func (*Client) Post

func (c *Client) Post(url string, mimetype string, body io.Reader) (*http.Response, error)

Post makes a POST request to a given URL

type Conn

type Conn interface {
	client.Client
	io.Closer
	SetDeadline(time.Time) error
	SetReadDeadline(time.Time) error
	SetWriteDeadline(time.Time) error
	Release()
}

Conn is an interface implemented by a connection

type Dialer

type Dialer interface {
	// Dial dials a remote http server returning a Conn.
	Dial(protocol, addr string, options *Options) (Conn, error)
	DialWithProxy(protocol, addr, proxyURL string, timeout time.Duration) (Conn, error)
	// DialTimeout dials a remote http server with timeout returning a Conn.
	DialTimeout(protocol, addr string, timeout time.Duration, options *Options) (Conn, error)
}

Dialer can dial a remote HTTP server.

type Options

type Options struct {
	Timeout                time.Duration
	FollowRedirects        bool
	MaxRedirects           int
	AutomaticHostHeader    bool
	AutomaticContentLength bool
	CustomHeaders          client.Headers
	ForceReadAllBody       bool // ignores content length and reads all body
	CustomRawBytes         []byte
	Proxy                  string
	ProxyDialTimeout       time.Duration
	SNI                    string
}

Options contains configuration options for rawhttp client

type RedirectStatus

type RedirectStatus struct {
	FollowRedirects bool
	MaxRedirects    int
	Current         int
}

RedirectStatus is the current redirect status for the request

type StatusError

type StatusError struct {
	client.Status
}

StatusError is a HTTP status error object

func (*StatusError) Error

func (s *StatusError) Error() string

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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