HTTP/2 Header Encoding in Swift
Swift
Latest commit e279e5a Sep 13, 2016 @kylef Support Swift 3.0
Permalink
Failed to load latest commit information.
Sources
Tests
.gitignore
.swift-version
LICENSE
Package.swift
README.md

README.md

HTTP/2 Header Encoding in Swift

HPACK (RFC 7541) implementation in Swift.

Usage

Encoding a set of headers

let headers: [Header] = [
  (":method", "GET"),
  (":path", "/"),
  ("Accept", "application/json"),
]

let encoder = hpack.Encoder()
let bytes = try encoder.encode(headers)

print(bytes)

Secure headers

You may also pass a secure parameter when encoding a header, which allows you to prevent the header from being added to the header table.

let bytes = try encoder.encode([
  ("secret", "secret-key", true),
])

print(bytes)

Decoding a set of headers

let bytes: [UInt8] = [130]

let decoder = hpack.Decoder()
let headers = try decoder.decode(bytes)

for header in headers {
  print(header.name)
  print(header.value)
}