https

package
v0.0.0-...-4cf4c4f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	// URL is the HTTPs endpoint.
	URL string
	// Method is the HTTP method to use in the request.
	Method string
	// TrustedCertFingerprint is the sha256 hash of a server's trusted
	// (self-signed) TLS certificate.
	TrustedCertFingerprint []byte
}

Request encapsulates an HTTPs request.

type Response

type Response struct {
	// Data is the received request payload.
	Data []byte
	// HTTPStatusCode is the HTTP status code of the response.
	HTTPStatusCode int
	// RedirectURL is the Location header of a HTTP redirect response.
	RedirectURL string
}

Response encapsulates an HTTPs response.

func Fetch

func Fetch(req Request) (*Response, error)

Fetch retrieves data from an HTTPs server that may have a self-singed TLS certificate. Pins the trusted certificate when req.TrustedCertFingerprint is non-empty. Follows up to 10 HTTPs redirects and sets the response's RedirectURL to the last Location header URL when the status code is a permantent redirect. Returns an error if req.URL is a non-HTTPS URL, if there is a connection error to the server, or if reading the response fails.

Jump to

Keyboard shortcuts

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