httpu

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxMessageBytes = 2048
)
View Source
const LocalAddressHeader = "goupnp-local-address"

Variables

This section is empty.

Functions

func Serve

func Serve(l net.PacketConn, handler Handler) error

Serve messages received on the given packet listener to the given handler.

Types

type ClientInterface

type ClientInterface interface {
	// Do performs a request. The timeout is how long to wait for before returning
	// the responses that were received. An error is only returned for failing to
	// send the request. Failures in receipt simply do not add to the resulting
	// responses.
	Do(
		req *http.Request,
		timeout time.Duration,
		numSends int,
	) ([]*http.Response, error)
}

ClientInterface is the general interface provided to perform HTTP-over-UDP requests.

type ClientInterfaceCtx

type ClientInterfaceCtx interface {
	// DoWithContext performs a request. If the input request has a
	// deadline, then that value will be used as the timeout for how long
	// to wait before returning the responses that were received. If the
	// request's context is canceled, this method will return immediately.
	//
	// If the request's context is never canceled, and does not have a
	// deadline, then this function WILL NEVER RETURN. You MUST set an
	// appropriate deadline on the context, or otherwise cancel it when you
	// want to finish an operation.
	//
	// An error is only returned for failing to send the request. Failures
	// in receipt simply do not add to the resulting responses.
	DoWithContext(
		req *http.Request,
		numSends int,
	) ([]*http.Response, error)
}

ClientInterfaceCtx is the equivalent of ClientInterface, except with methods taking a context.Context parameter.

type HTTPUClient

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

HTTPUClient is a client for dealing with HTTPU (HTTP over UDP). Its typical function is for HTTPMU, and particularly SSDP.

func NewHTTPUClient

func NewHTTPUClient() (*HTTPUClient, error)

NewHTTPUClient creates a new HTTPUClient, opening up a new UDP socket for the purpose.

func NewHTTPUClientAddr

func NewHTTPUClientAddr(addr string) (*HTTPUClient, error)

NewHTTPUClientAddr creates a new HTTPUClient which will broadcast packets from the specified address, opening up a new UDP socket for the purpose

func (*HTTPUClient) Close

func (httpu *HTTPUClient) Close() error

Close shuts down the client. The client will no longer be useful following this.

func (*HTTPUClient) Do

func (httpu *HTTPUClient) Do(
	req *http.Request,
	timeout time.Duration,
	numSends int,
) ([]*http.Response, error)

Do implements ClientInterface.Do.

Note that at present only one concurrent connection will happen per HTTPUClient.

func (*HTTPUClient) DoWithContext

func (httpu *HTTPUClient) DoWithContext(
	req *http.Request,
	numSends int,
) ([]*http.Response, error)

DoWithContext implements ClientInterfaceCtx.DoWithContext.

Make sure to read the documentation on the ClientInterfaceCtx interface regarding cancellation!

type Handler

type Handler interface {
	// ServeMessage is called for each HTTPU message received. peerAddr contains
	// the address that the message was received from.
	ServeMessage(r *http.Request)
}

Handler is the interface by which received HTTPU messages are passed to handling code.

type HandlerFunc

type HandlerFunc func(r *http.Request)

HandlerFunc is a function-to-Handler adapter.

func (HandlerFunc) ServeMessage

func (f HandlerFunc) ServeMessage(r *http.Request)

type MultiClient

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

MultiClient dispatches requests out to all the delegated clients.

func NewMultiClient

func NewMultiClient(delegates []ClientInterface) *MultiClient

NewMultiClient creates a new MultiClient that delegates to all the given clients.

func (*MultiClient) Do

func (mc *MultiClient) Do(
	req *http.Request,
	timeout time.Duration,
	numSends int,
) ([]*http.Response, error)

Do implements ClientInterface.Do.

type MultiClientCtx

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

MultiClientCtx dispatches requests out to all the delegated clients.

func NewMultiClientCtx

func NewMultiClientCtx(delegates []ClientInterfaceCtx) *MultiClientCtx

NewMultiClient creates a new MultiClient that delegates to all the given clients.

func (*MultiClientCtx) DoWithContext

func (mc *MultiClientCtx) DoWithContext(
	req *http.Request,
	numSends int,
) ([]*http.Response, error)

DoWithContext implements ClientInterfaceCtx.DoWithContext.

type Server

type Server struct {
	Addr            string         // UDP address to listen on
	Multicast       bool           // Should listen for multicast?
	Interface       *net.Interface // Network interface to listen on for multicast, nil for default multicast interface
	Handler         Handler        // handler to invoke
	MaxMessageBytes int            // maximum number of bytes to read from a packet, DefaultMaxMessageBytes if 0
}

A Server defines parameters for running an HTTPU server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the UDP network address srv.Addr. If srv.Multicast is true, then a multicast UDP listener will be used on srv.Interface (or default interface if nil).

func (*Server) Serve

func (srv *Server) Serve(l net.PacketConn) error

Serve messages received on the given packet listener to the srv.Handler.

Jump to

Keyboard shortcuts

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