transport

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// AcceptHeader specifies the content type that the client is expecting.
	AcceptHeader = "Accept"

	// LDPlusJSONContentType specifies the linked data plus JSON content type.
	LDPlusJSONContentType = `application/ld+json`

	// ActivityStreamsContentType is the content type used for activity streams messages.
	ActivityStreamsContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type NoOpSigner

type NoOpSigner struct{}

NoOpSigner is a signer that does nothing. This signer should only be used by tests.

func DefaultSigner

func DefaultSigner() *NoOpSigner

DefaultSigner returns a default, no-op signer. This signer should only be used by tests.

func (*NoOpSigner) SignRequest

func (s *NoOpSigner) SignRequest(pubKeyID string, req *http.Request) error

SignRequest does nothing.

type Option

type Option func(options *options)

Option defines a transport option.

func WithHeader

func WithHeader(name string, values ...string) Option

WithHeader specifies a header in the HTTP request.

type Request

type Request struct {
	URL    *url.URL
	Header http.Header
}

Request contains the destination URL and headers.

func NewRequest

func NewRequest(toURL *url.URL, opts ...Option) *Request

NewRequest returns a new request.

type Signer

type Signer interface {
	SignRequest(pubKeyID string, req *http.Request) error
}

Signer signs an HTTP request and adds the signature to the header of the request.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport implements a client-side transport that Gets and Posts requests using HTTP signatures.

func Default

func Default() *Transport

Default returns a default transport that uses the default HTTP client and no HTTP signatures. This transport should only be used by tests.

func New

func New(client httpClient, publicKeyID *url.URL, getSigner, postSigner Signer, tm authTokenManager) *Transport

New returns a new transport.

func (*Transport) Get

func (t *Transport) Get(ctx context.Context, r *Request) (*http.Response, error)

Get sends an HTTP GET. The HTTP request is first signed and the signature is added to the request header.

func (*Transport) Post

func (t *Transport) Post(ctx context.Context, r *Request, payload []byte) (*http.Response, error)

Post posts an HTTP request. The HTTP request is first signed and the signature is added to the request header.

Jump to

Keyboard shortcuts

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