Categorygithub.com/xenking/http2
modulepackage
0.2.0
Repository: https://github.com/xenking/http2.git
Documentation: pkg.go.dev

# README

HTTP2

http2 is an implementation of HTTP/2 protocol for fasthttp.

Download

go get github.com/xenking/[email protected]

Help

If you need any help to set up, contributing or understanding this repo, you can contact me on gofiber's Discord.

How to use the server?

The server can only be used if your server supports TLS. Then, you can call ConfigureServer.

package main

import (
	"github.com/valyala/fasthttp"
	"github.com/xenking/http2"
)

func main() {
    s := &fasthttp.Server{
        Handler: yourHandler,
        Name:    "HTTP2 test",
    }

    http2.ConfigureServer(s, http2.ServerConfig{})
    
    s.ListenAndServeTLS(...)
}

How to use the client?

The HTTP/2 client only works with the HostClient.

package main

import (
        "fmt"
        "log"

        "github.com/xenking/http2"
        "github.com/valyala/fasthttp"
)

func main() {
        hc := &fasthttp.HostClient{
                Addr:  "api.binance.com:443",
        }

        if err := http2.ConfigureClient(hc, http2.ClientOpts{}); err != nil {
                log.Printf("%s doesn't support http/2\n", hc.Addr)
        }

        statusCode, body, err := hc.Get(nil, "https://api.binance.com/api/v3/time")
        if err != nil {
                log.Fatalln(err)
        }

        fmt.Printf("%d: %s\n", statusCode, body)
}

Benchmarks

Benchmark code here.

fasthttp2

$  h2load --duration=10 -c10 -m1000 -t 4 https://localhost:8443
[...]
finished in 10.01s, 533808.90 req/s, 33.09MB/s
requests: 5338089 total, 5348089 started, 5338089 done, 5338089 succeeded, 0 failed, 0 errored, 0 timeout
status codes: 5338089 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 330.90MB (346976335) total, 137.45MB (144128403) headers (space savings 57.14%), 101.82MB (106761780) data
                     min         max         mean         sd        +/- sd
time for request:     1.06ms    101.25ms     17.16ms     11.06ms    75.19%
time for connect:     5.21ms     17.36ms     12.60ms      3.56ms    70.00%
time to 1st byte:    11.32ms     35.27ms     18.84ms      6.85ms    80.00%
req/s           :   48976.50    59084.92    53359.02     3657.52    60.00%

net/http2

$  h2load --duration=10 -c10 -m1000 -t 4 https://localhost:8443
[...]
finished in 10.01s, 124812.90 req/s, 5.00MB/s
requests: 1248129 total, 1258129 started, 1248129 done, 1248129 succeeded, 0 failed, 0 errored, 0 timeout
status codes: 1248247 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 50.00MB (52426258) total, 4.76MB (4995738) headers (space savings 95.83%), 23.81MB (24962580) data
                     min         max         mean         sd        +/- sd
time for request:      141us    140.75ms     19.69ms     11.34ms    76.79%
time for connect:     3.89ms     13.30ms      9.71ms      2.78ms    70.00%
time to 1st byte:    11.02ms     50.13ms     20.13ms     11.24ms    90.00%
req/s           :   11909.97    13162.89    12479.53      373.71    70.00%

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
AcquireFrameHeader gets a FrameHeader from pool.
AcquireHeaderField gets HeaderField from the pool.
AcquireHPACK gets HPACK from pool.
ConfigureClient configures the fasthttp.HostClient to run over HTTP/2.
ConfigureServer configures the fasthttp server to handle HTTP/2 connections.
ConfigureServerAndConfig configures the fasthttp server to handle HTTP/2 connections and your own tlsConfig file.
Handshake performs an HTTP/2 handshake.
HuffmanDecode decodes src into dst using Huffman codes.
HuffmanEncode encodes src into dst using Huffman algorithm.
NewConn returns a new HTTP/2 connection.
NewError creates a new Error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ReadPreface reads the connection initialisation preface.
No description provided by the author
ReleaseFrameHeader reset and puts fr to the pool.
ReleaseHeaderField puts HeaderField to the pool.
ReleaseHPACK puts HPACK to the pool.
No description provided by the author
WritePreface writes HTTP/2 preface to the wr.

# Constants

No description provided by the author
No description provided by the author
DefaultFrameSize FrameHeader default size http://httpwg.org/specs/rfc7540.html#FrameHeader.
No description provided by the author
No description provided by the author
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
No description provided by the author
Frame Flag (described along the frame types) More flags have been ignored due to redundancy.
Frame Flag (described along the frame types) More flags have been ignored due to redundancy.
Frame Flag (described along the frame types) More flags have been ignored due to redundancy.
Frame Flag (described along the frame types) More flags have been ignored due to redundancy.
Frame Flag (described along the frame types) More flags have been ignored due to redundancy.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
H2Clean is the string used in HTTP headers by the client to upgrade the connection.
H2TLSProto is the string used in ALPN-TLS negotiation.
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
No description provided by the author
No description provided by the author
No description provided by the author
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ErrServerSupport indicates whether the server supports HTTP/2 or not.
No description provided by the author
No description provided by the author
No description provided by the author
ErrUnknownFrameType This error codes must be used with FrameGoAway.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
ClientOpts defines the client options for the HTTP/2 connection.
Conn represents a raw HTTP/2 connection over TLS + TCP.
ConnOpts defines the connection options.
Continuation represents the Continuation frame.
Ctx represents a context for a stream.
Data defines a FrameData Data frames can have the following flags: END_STREAM PADDED https://tools.ietf.org/html/rfc7540#section-6.1.
Dialer allows creating HTTP/2 connections by specifying an address and tls configuration.
Error defines the HTTP/2 errors, composed by the code and debug data.
FrameHeader is frame representation of HTTP2 protocol Use AcquireFrameHeader instead of creating FrameHeader every time if you are going to use FrameHeader as your own and ReleaseFrameHeader to delete the FrameHeader FrameHeader instance MUST NOT be used from different goroutines.
GoAway https://tools.ietf.org/html/rfc7540#section-6.8.
HeaderField represents a field in HPACK tables.
Headers defines a FrameHeaders https://tools.ietf.org/html/rfc7540#section-6.2.
HPACK represents header compression methods to encode and decode header fields in HTTP/2.
Ping https://tools.ietf.org/html/rfc7540#section-6.7.
Priority represents the Priority frame.
PushPromise https://tools.ietf.org/html/rfc7540#section-6.6.
RstStream https://tools.ietf.org/html/rfc7540#section-6.4.
Server defines an HTTP/2 entity that can handle HTTP/2 connections.
ServerConfig ...
Settings is the options to establish between endpoints when starting the connection.
No description provided by the author
WindowUpdate https://tools.ietf.org/html/rfc7540#section-6.9.
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

ErrorCode defines the HTTP/2 error codes: Error codes are defined here http://httpwg.org/specs/rfc7540.html#ErrorCodes Errors must be uint32 because of FrameReset.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author