http

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

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 stdhttp.RoundTrip and can be used as custom transport with Go stdhttp.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 stdhttp request and obtain the response.

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

t := &stdhttp.Transport{}
t.RegisterProtocol("libp2p", p2phttp.NewTransport(host, ProtocolOption(DefaultP2PProtocol)))
c := &stdhttp.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