Skip to content

kylef-archive/hpack.swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

Releases

No releases published

Packages

No packages published

Languages