h3conn

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHTTP3NotSupported = fmt.Errorf("HTTP3 not supported")

ErrHTTP3NotSupported is returned by Accept if the client connection does not support HTTP3 connection. The server than can response to the client with an HTTP1.1 as he wishes.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Method sets the HTTP method for the dial
	// The default method, if not set, is HTTP POST.
	Method string
	// Header enables sending custom headers to the server
	Header http.Header
	// Client is a custom HTTP client to be used for the connection.
	// The client must have an http3.Transport as it's transport.
	Client *http.Client
}

Client provides HTTP3 client side connection with special arguments

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, urlStr string) (*Conn, *http.Response, error)

Connect establishes a full duplex communication with an HTTP3 server with custom client. See h2conn.Connect documentation for more info.

type Conn

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

Conn is client/server symmetric connection. It implements the io.Reader/io.Writer/io.Closer to read/write or close the connection to the other side. It also has a Send/Recv function to use channels to communicate with the other side.

func Accept

func Accept(w http.ResponseWriter, r *http.Request) (*Conn, error)

Accept is used on a server http.Handler to extract a full-duplex communication object with the client. The server connection will be closed when the http handler function will return. If the client does not support HTTP3, an ErrHTTP3NotSupported is returned.

Usage:

     func (w http.ResponseWriter, r *http.Request) {
         conn, err := h2conn.Accept(w, r)
         if err != nil {
		        log.Printf("Failed creating http3 connection: %s", err)
		        http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		        return
	        }
         // use conn
     }

func Connect

func Connect(ctx context.Context, urlStr string) (*Conn, *http.Response, error)

Connect establishes a full duplex communication with an HTTP3 server.

Usage:

conn, resp, err := h2conn.Connect(ctx, url)
if err != nil {
    log.Fatalf("Initiate client: %s", err)
}
if resp.StatusCode != http.StatusOK {
    log.Fatalf("Bad status code: %d", resp.StatusCode)
}
defer conn.Close()

// use conn

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection

func (*Conn) Read

func (c *Conn) Read(data []byte) (int, error)

Read reads data from the connection

func (*Conn) Write

func (c *Conn) Write(data []byte) (int, error)

Write writes data to the connection

type Server

type Server struct {
	StatusCode int
}

Server can "accept" an http3 connection to obtain a read/write object for full duplex communication with a client.

func (*Server) Accept

func (u *Server) Accept(w http.ResponseWriter, r *http.Request) (*Conn, error)

Accept is used on a server http.Handler to extract a full-duplex communication object with the client. See h2conn.Accept documentation for more info.

Jump to

Keyboard shortcuts

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