HTTP/2 HPACK Compression Go Library

LilLarkin 8年前發布 | 7K 次閱讀 HTTP 哈夫曼編碼 Go語言 前端技術

來自: https://github.com/chrismoos/hpack

HPACK library

This library implements RFC7541 , HPACK: Header Compression for HTTP/2 , which includes:

  • Primitive Type Representations
    • Variable integer sizes (with prefix lengths)
    • String literals (incl. Huffman decoding)
  • Static & Dynamic indexes
  • Dynamic Table evictions
  • Header block parsing

Usage

Most users of this library will be implementing HTTP/2.

decoder := hpack.NewDecoder(negotiatedDynamicTableSizeMax)
headerBlock := recvHeaderBlockAndContinuations()
headers, err := decoder.Decode(headerBlock)

The Decode function expects a complete header block. HTTP/2 specifies that a header block can be split across multiple frames, in a HEADER or PUSH_PROMISE frame plus optional CONTINUATION frames.

Users should concatenate the header block fragments together and only call ParseHeadersBlock when a frame with the END_HEADERS flag is received.

Development

Generating Huffman lookup tables

The lookup tables are code generated from the Huffman codes in the HPACK specification. This ensures the lookup tables are available at runtime with no initialization required.

Run the following command to generate the lookup tables used for Huffman decoding:

go run cmd/generate_huffman_tables/main.go | gofmt > huffman_tables.go

License

Copyright 2016 Chris Moos

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</pre> </article>

 本文由用戶 LilLarkin 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!