Documentation ¶
Index ¶
- Variables
- type Client
- type Conn
- func (c *Conn) Close() error
- func (s *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(data []byte) (int, error)
- func (s *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(data []byte) (int, error)
- type Server
Constants ¶
This section is empty.
Variables ¶
var ErrHTTP2NotSupported = fmt.Errorf("HTTP2 not supported")
ErrHTTP2NotSupported is returned by Accept if the client connection does not support HTTP2 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 http2.Transport as it's transport. Client *http.Client }
Client provides HTTP2 client side connection with special arguments
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 ¶
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 HTTP2, an ErrHTTP2NotSupported is returned.
Usage:
func (w http.ResponseWriter, r *http.Request) { conn, err := h2conn.Accept(w, r) if err != nil { log.Printf("Failed creating http2 connection: %s", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } // use conn }
func Connect ¶
Connect establishes a full duplex communication with an HTTP2 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) RemoteAddr ¶
RemoteAddr is used to get the address of remote end of the underlying connection