http

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultP2PProtocol protocol.ID = "/libp2p-http"

DefaultP2PProtocol is used to tag and identify streams handled by go-libp2p-http

Functions

func Connect

func Connect()

func Start

func Start()

Types

type Option

type Option func(o *options)

Option allows to set the libp2p transport options.

func ProtocolOption

func ProtocolOption(p protocol.ID) Option

ProtocolOption sets the Protocol Tag associated to the libp2p roundtripper.

type RoundTripper

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

RoundTripper implemenets http.RoundTrip and can be used as custom transport with Go http.Client.

func NewTransport

func NewTransport(h host.Host, opts ...Option) *RoundTripper

NewTransport returns a new RoundTripper which uses the provided libP2P host to perform an http request and obtain the response.

The typical use case for NewTransport is to register the "libp2p" protocol with a Transport, as in:

t := &http.Transport{}
t.RegisterProtocol("libp2p", p2phttp.NewTransport(host, ProtocolOption(DefaultP2PProtocol)))
c := &http.Client{Transport: t}
res, err := c.Get("libp2p://Qmaoi4isbcTbFfohQyn28EiYM5CDWQx9QRCjDh3CTeiY7P/index.html")
...

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(r *nethttp.Request) (*nethttp.Response, error)

RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.

Jump to

Keyboard shortcuts

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