chttp

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: Unlicense Imports: 4 Imported by: 3

README

chttp

Go Reference

Cooked HTTP — a standard golang HTTP Client wrapper that adds a cookie jar with user-defined cookies, and a customised transport.

Simple usage:

import "github.com/rusq/chttp"

func getSomething() error {
	cookies := readFromFile()
	cl := chttp.New("https://slack.com", cookies)

	resp, err := cl.Get("url") // will execute with the cookies
	if err != nil {
		return err
	}
	// do something with resp
	return nil
}

See package documentation if you'd like to read more.

Documentation

Overview

Package chttp (Cooked HTTP) provides a wrapper around http.Client with cookies. It also allows to use custom Transport, which wraps the default transport and calls the user-defined function before and after the request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must added in v1.0.1

func Must(cl *http.Client, err error) *http.Client

Must is a helper function to panic on error.

func New

func New(cookieDomain string, cookies []*http.Cookie) (*http.Client, error)

New returns the HTTP client with cookies and default transport.

func NewWithTransport

func NewWithTransport(cookieDomain string, cookies []*http.Cookie, rt http.RoundTripper) (*http.Client, error)

NewWithTransport inits the HTTP client with cookies. It allows to use the custom Transport.

Types

type Transport

type Transport struct {

	// BeforeReq is called before the request.
	BeforeReq func(req *http.Request)
	// AfterReq is called after the request.
	AfterReq func(resp *http.Response, req *http.Request)
	// contains filtered or unexported fields
}

Transport is a simple wrapper for http.RoundTripper to do something before and after RoundTrip.

func NewTransport

func NewTransport(tr http.RoundTripper) *Transport

NewTransport returns a new Transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip implements http.RoundTripper. It calls BeforeReq before the request and AfterReq after the request.

Jump to

Keyboard shortcuts

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