Skip to content

Commit

Permalink
Fix documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 10, 2024
1 parent 79ff337 commit 373fe21
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
2 changes: 2 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
group :maintenance, optional: true do
gem "bake-gem"
gem "bake-modernize"

gem "utopia-project"
end
50 changes: 50 additions & 0 deletions guides/getting-started/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Getting Started

This guide explains how to use the `protocol-hpack` gem to compress and decompress HTTP/2 headers using HPACK.

## Installation

Add the gem to your project:

``` shell
$ bundle add protocol-hpack
```

Or install it yourself as:

``` shell
$ gem install protocol-hpack
```

## Core Concepts

The `protocol-hpack` gem provides a {ruby Protocol::HPACK::Compressor} and {ruby Protocol::HPACK::Decompressor} for HTTP 2 headers, HPACK, as defined by [RFC7541](https://tools.ietf.org/html/rfc7541).

HPACK is a compression format designed specifically for HTTP/2 to reduce header size and improve performance by minimizing overhead. It addresses the redundancy and repetitive nature of HTTP/1.x headers by employing a static table of common header fields and a dynamic table that evolves based on the headers seen in a particular connection. Headers are encoded into a more compact format, using Huffman coding for literal values and indexing to refer to previously transmitted headers. This approach significantly reduces the amount of data transmitted between client and server, especially in contexts where headers are similar or identical across multiple requests and responses. HPACK's design directly tackles the inefficiencies of HTTP/1.x headers, providing a more bandwidth-efficient and faster web experience by optimizing the way headers are transmitted in HTTP/2 connections.

### Compressing Headers

``` ruby
require 'protocol/hpack'

buffer = String.new.b
compressor = Protocol::HPACK::Compressor.new(buffer)

compressor.encode([['content-length', '5']])
=> "\\\x015"
```

### Decompressing Headers

Reusing `buffer` from above:

``` ruby
require 'protocol/hpack'

# Buffer from above...
buffer = "\\\x015"
decompressor = Protocol::HPACK::Decompressor.new(buffer)

decompressor.decode
=> [["content-length", "5"]]
```
2 changes: 2 additions & 0 deletions guides/links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
getting-started:
order: 1
6 changes: 5 additions & 1 deletion protocol-hpack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
spec.name = "protocol-hpack"
spec.version = Protocol::HPACK::VERSION

spec.summary = "A compresssor and decompressor for HTTP 2.0 HPACK."
spec.summary = "A compresssor and decompressor for HTTP/2's HPACK format."
spec.authors = ["Samuel Williams", "Ilya Grigorik", "Tamir Duberstein", "Kaoru Maeda", "Tiago Cardoso", "Byron Formwalt", "Cyril Roelandt", "Daniel Morrison", "Felix Yan", "George Ulmer", "Jingyi Chen", "Justin Mazzocchi", "Kenichi Nakamura", "Kien Nguyen Trung", "Olle Jonsson"]
spec.license = "MIT"

Expand All @@ -15,6 +15,10 @@ Gem::Specification.new do |spec|

spec.homepage = "https://github.com/socketry/http-hpack"

spec.metadata = {
"documentation_uri" => "https://socketry.github.io/protocol-hpack/",
}

spec.files = Dir.glob(['{lib,tasks}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.0"
Expand Down
27 changes: 2 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,9 @@ Or install it yourself as:

## Usage

### Compressing Headers
Please see the [project documentation](https://socketry.github.io/protocol-hpack/) for more details.

``` ruby
require 'protocol/hpack'

buffer = String.new.b
compressor = Protocol::HPACK::Compressor.new(buffer)

compressor.encode([['content-length', '5']])
=> "\\\x015"
```

### Decompressing Headers

Reusing `buffer` from above:

``` ruby
require 'protocol/hpack'

# Buffer from above...
buffer = "\\\x015"
decompressor = Protocol::HPACK::Decompressor.new(buffer)

decompressor.decode
=> [["content-length", "5"]]
```
- [Getting Started](https://socketry.github.io/protocol-hpack/guides/getting-started/index) - This guide explains how to use the `protocol-hpack` gem to compress and decompress HTTP/2 headers using HPACK.

## Contributing

Expand Down

0 comments on commit 373fe21

Please sign in to comment.