Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hpack Laravel Package

amphp/hpack

Fast HPACK (HTTP/2 header compression) implementation for PHP by amphp. Provides efficient encoding/decoding of header blocks with dynamic tables, Huffman coding, and compliance-focused behavior, suitable for high-performance HTTP/2 clients and servers.

View on GitHub
Deep Wiki
Context7

Getting Started

amphp/hpack is a low-level library for HTTP/2 header compression using HPACK (RFC 7541). It's primarily intended for use by HTTP/2 client/server implementations (e.g., amphp/http-server, amphp/http-client). To start:

  • Install via composer require amphp/hpack
  • Examine src/ for the two core classes: StaticTable (immutable header table) and DynamicTable (mutable, per-connection)
  • Use Encoder and Decoder classes to compress/decompress header sets
  • Minimal example:
    use function Amp\Http\Server\Encoder;
    use function Amp\Http\Server\Decoder;
    
    $encoder = new Encoder();
    $decoder = new Decoder();
    
    $headers = [[':method', 'GET'], [':path', '/']];  
    $encoded = $encoder->encode($headers); // returns binary string  
    $decoded = $decoder->decode($encoded); // returns original headers array  
    

Check examples/ for basic round-trip use and consult unit tests (tests/) for edge cases.

Implementation Patterns

  • Stateful connections: Reuse Encoder/Decoder instances per-connection (HPACK is stateful due to dynamic table).
  • Stream-agnostic: Works with raw binary strings—ideal for integration into async I/O (e.g., amphp/socket, ReactPHP).
  • Integration with HTTP/2 stacks: Typically used upstream of framing logic (e.g., after header generation but before writing to the HTTP/2 data frame).
  • Memory-conscious configs: Control dynamic table size via Decoder/Encoder constructors (defaults to 4096 bytes; reduce for memory-constrained environments).
  • Testing: Pair with amphp/http2 to validate compliance via unit tests (e.g., RFC test vectors in tests/RfcTest.php).

Gotchas and Tips

  • Not a standalone HTTP library: This is not a high-level tool—it requires careful orchestration with HTTP/2 frame layers. Misusing it (e.g., resetting dynamic table incorrectly) breaks compliance.
  • Dynamic table size updates (RFC 7541 § 6.3): Encoder emits DynamicTableSizeUpdate frames implicitly, but Decoder must be fed all table size change notifications in order. Ensure your HTTP/2 frame handler forwards them correctly.
  • Binary-safe decoding: decode() throws Amp\Http\Server\HttpException on malformed input—always wrap in try/catch. Errors often indicate out-of-sync dynamic tables.
  • Performance: HPACK compression is CPU-light but allocation-heavy; reuse objects and avoid per-request instantiation in high-throughput services.
  • Extensibility: Extend Encoder/Decoder to inject custom header handling (e.g., logging, sensitive header redaction), but do not modify static/dynamic table internals.
  • Debugging: Enable HPACK_DEBUG (if compiled with debug symbols) or log raw binary before/after encoding—compare with Wireshark captures for discrepancies.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport