httpclient

package
v0.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package httpclient owns the process-wide outbound HTTP client so every outbound call shares one timeout and one seam tests can replace. It depends on nothing else in the tree, which is what lets low-level packages (jwtutils) make network calls without importing the utils grab-bag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchBounded

func FetchBounded(ctx context.Context, url string, c Client, maxBytes int64) ([]byte, error)

FetchBounded GETs url and reads at most maxBytes of the body, so a hostile or misbehaving peer cannot stream unbounded data into memory. A nil client uses the shared one.

func Set

func Set(c Client)

Set replaces the shared client.

func SetSSRFSafe

func SetSSRFSafe(client Client)

Types

type Client

type Client interface {
	Do(req *http.Request) (res *http.Response, err error)
	Get(url string) (res *http.Response, err error)
	Post(urstring, bodyType string, body io.Reader) (res *http.Response, err error)
	PostForm(url string, values url.Values) (res *http.Response, err error)
	Head(url string) (res *http.Response, err error)
}

Client is the outbound HTTP surface. An interface so tests substitute a transport-level double.

func Get

func Get() Client

Get returns the shared client, building the default on first use so a caller never gets nil because initialization order put it ahead of the setup path.

func GetSSRFSafe

func GetSSRFSafe() Client

GetSSRFSafe returns a client for fetching URLs an untrusted caller controls. Unlike Get it refuses redirects and refuses to connect to any non-public address, so it must not be used for deliberate link-local calls such as the ECS task-metadata endpoint.

Jump to

Keyboard shortcuts

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