httpu

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: BSD-2-Clause Imports: 11 Imported by: 80

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 added in v1.0.1

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 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.

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 added in v1.0.1

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

MultiClient dispatches requests out to all the delegated clients.

func NewMultiClient added in v1.0.1

func NewMultiClient(delegates []ClientInterface) *MultiClient

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

func (*MultiClient) Do added in v1.0.1

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

Do implements ClientInterface.Do.

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