httpclient

package
v0.0.0-...-2bad381 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package httpclient is Readeck's own HTTP client. It provides an http.RoundTripper with sensible defaults that can make outgoing requests look like they come from a browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToCache

func AddToCache(client *http.Client, url string, headers http.Header, body []byte)

AddToCache adds a URL, headers and body to an http.Client cache. If the client's transport is not a CacheTransport instance, it does nothing.

func IsInCache

func IsInCache(client *http.Client, url string) bool

IsInCache returns true if a URL exists in an http.Client cache. If the client's transport is not a CacheTransport instance, it does nothing.

func New

func New() *http.Client

New returns a new client with an empty cookie storage and a Transport instance.

func NewCacheClient

func NewCacheClient(check func(*http.Request) bool) *http.Client

NewCacheClient returns a new http.Client with a CacheTransport round tripper. The "check" function, when not null, can be used to exclude a request from any cache request.

Types

type CacheTransport

type CacheTransport struct {
	*Transport
	sync.RWMutex
	// contains filtered or unexported fields
}

CacheTransport is a wrapper around Transport that adds a cache layer.

func (*CacheTransport) RoundTrip

func (t *CacheTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. When an entry is found in the cache, it sends a response made out of it. Otherwise, it calls the wrapped RoundTrip method.

type Transport

type Transport struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

Transport wraps an http.RoundTripper.

func (*Transport) Log

func (t *Transport) Log() *slog.Logger

Log returns the transport's logger.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It checks if the destination IP is allowed, adds default headers and logs (debug-10 level) every request.

func (*Transport) SetHeader

func (t *Transport) SetHeader(fn func(h http.Header))

SetHeader receives a function that can manipulate the transport's default headers.

func (*Transport) SetLogger

func (t *Transport) SetLogger(l *slog.Logger)

SetLogger sets the transport's logger.

Jump to

Keyboard shortcuts

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