github.com/useflyent/fhttp@v0.0.0-20211004035111-333f430cfbbf/README.md (about)

     1  # fhttp
     2  
     3  # Features
     4  
     5  ## Ordered Headers
     6  
     7  The package allows for both pseudo header order and normal header order. Most of the code is from this [this Pull Request](https://go-review.googlesource.com/c/go/+/105755/).
     8  
     9  **Note on HTTP/1.1 header order**
    10  Although the header key is capitalized, the header order slice must be in lowercase.
    11  ```go
    12  	req.Header = http.Header{
    13  		"X-NewRelic-ID":         {"12345"},
    14  		"x-api-key":             {"ABCDE12345"},
    15  		"MESH-Commerce-Channel": {"android-app-phone"},
    16  		"mesh-version":          {"cart=4"},
    17  		"X-Request-Auth":        {"hawkHeader"},
    18  		"X-acf-sensor-data":     {"3456"},
    19  		"Content-Type":          {"application/json; charset=UTF-8"},
    20  		"Accept":                {"application/json"},
    21  		"Transfer-Encoding":     {"chunked"},
    22  		"Host":                  {"example.com"},
    23  		"Connection":            {"Keep-Alive"},
    24  		"Accept-Encoding":       {"gzip"},
    25  		HeaderOrderKey: {
    26  			"x-newrelic-id",
    27  			"x-api-key",
    28  			"mesh-commerce-channel",
    29  			"mesh-version",
    30  			"user-agent",
    31  			"x-request-auth",
    32  			"x-acf-sensor-data",
    33  			"transfer-encoding",
    34  			"content-type",
    35  			"accept",
    36  			"host",
    37  			"connection",
    38  			"accept-encoding",
    39  		},
    40  		PHeaderOrderKey: {
    41  			":method",
    42  			":path",
    43  			":authority",
    44  			":scheme",
    45  		},
    46  	}
    47  ```
    48  
    49  ## Connection settings
    50  
    51  fhhtp has Chrome-like connection settings, as shown below:
    52  
    53  ```text
    54  SETTINGS_HEADER_TABLE_SIZE = 65536 (2^16)
    55  SETTINGS_ENABLE_PUSH = 1
    56  SETTINGS_MAX_CONCURRENT_STREAMS = 1000
    57  SETTINGS_INITIAL_WINDOW_SIZE = 6291456
    58  SETTINGS_MAX_FRAME_SIZE = 16384 (2^14)
    59  SETTINGS_MAX_HEADER_LIST_SIZE = 262144 (2^18)
    60  ```
    61  
    62  The default net/http settings, on the other hand, are the following:
    63  
    64  ```text
    65  SETTINGS_HEADER_TABLE_SIZE = 4096
    66  SETTINGS_ENABLE_PUSH = 0
    67  SETTINGS_MAX_CONCURRENT_STREAMS = unlimited
    68  SETTINGS_INITIAL_WINDOW_SIZE = 4194304
    69  SETTINGS_MAX_FRAME_SIZE = 16384
    70  SETTINGS_MAX_HEADER_LIST_SIZE = 10485760
    71  ```
    72  
    73  The ENABLE_PUSH implementation was merged from [this Pull Request](https://go-review.googlesource.com/c/net/+/181497/).
    74  
    75  ## gzip, deflate, and br encoding
    76  
    77  `gzip`, `deflate`, and `br` encoding are all supported by the package.
    78  
    79  ## Pseudo header order
    80  
    81  fhttp supports pseudo header order for http2, helping mitigate fingerprinting. You can read more about how it works [here](https://www.akamai.com/uk/en/multimedia/documents/white-paper/passive-fingerprinting-of-http2-clients-white-paper.pdf).
    82  
    83  ## Backward compatible with net/http
    84  
    85  Although this library is an extension of `net/http`, it is also meant to be backward compatible. Replacing
    86  
    87  ```go
    88  import (
    89     "net/http"
    90  )
    91  ```
    92  
    93  with
    94  
    95  ```go
    96  import (
    97      http "github.com/useflyent/fhttp"
    98  )
    99  ```
   100  
   101  SHOULD not break anything.
   102  
   103  ## Versatile Content-Length and Transfer-Encoding headers
   104  
   105  fhttp user to set custom Content-Length and Transfer-Encoding headers of all types.
   106  
   107  ### To set an empty Content-Length header
   108  ```go
   109  req.Header = http.Header{
   110  	"Content-Length": {http.ContentLengthEmpty},
   111  }
   112  ```
   113  
   114  ### To ignore setting the Content-Length header
   115  ```go
   116  req.Header = http.Header{
   117      "Content-Length": {http.ContentLengthDelete},
   118  }
   119  ```
   120  
   121  Any Content-Length or Transfer-Encoding headers set will be prioritized and fhttp will not set proper Content-length or Transfer-Encoding headers
   122  
   123  ## Credits
   124  
   125  Special thanks to the following people for helping me with this project.
   126  
   127  * [cc](https://github.com/x04/) for guiding me when I first started this project and inspiring me with [cclient](https://github.com/x04/cclient)
   128  
   129  * [umasi](https://github.com/umasii) for being good rubber ducky and giving me tips for http2 headers