h2o

High-performance HTTP/2 client for Crystal with full protocol compliance, connection pooling, and advanced features. Written largely by Claude Code.

h2o

A high-performance HTTP/2 client for Crystal with full protocol compliance, connection pooling, and advanced features like HPACK compression and stream multiplexing. Optimized for production use with comprehensive CI testing.

Development Attribution

This project was developed heavily with the assistance of Claude Opus and Claude Sonnet 4. The codebase is largely (99%) generated by Claude Code through extensive collaboration, careful prompting, and iterative validation.

Important Notice: While this library is actively used in production environments and has been tested against multiple APIs and HTTP/2 endpoints, it should be considered experimental. This code represents the result of extensive AI-assisted development with careful validation and testing, but was not written by an expert in the HTTP/2 protocol or the Crystal programming language.

All functionality included in this library, including the Circuit Breaker and Circuit Breaker Persistence Adapters, are currently in use in production environments but should be considered somewhat experimental. Users should thoroughly test and validate the library for their specific use cases before production deployment.

Features

  • ๐Ÿš€ Full HTTP/2 Support: Complete implementation of RFC 7540
  • ๐Ÿ” TLS with ALPN: Automatic HTTP/2 negotiation via TLS ALPN
  • ๐Ÿ—œ๏ธ HPACK Compression: RFC 7541 compliant header compression
  • ๐Ÿ”€ Stream Multiplexing: Concurrent request handling over single connection
  • ๐ŸŠ Connection Pooling: Efficient connection reuse and management
  • ๐Ÿ“Š Flow Control: Both connection and stream-level flow control
  • โšก High Performance: Optimized for speed and low memory usage
  • ๐Ÿงช Comprehensive Tests: Full test coverage with integration tests
  • ๐Ÿ”„ Circuit Breaker: Built-in circuit breaker pattern for resilience

H2SPEC Compliance

h2o demonstrates 100% compliance with the HTTP/2 specification through comprehensive native testing:

Test Category Tests Passed Success Rate
Connection Preface (RFC 7540 ยง3.5) 4 4 โœ… 100%
Frame Format & Size (RFC 7540 ยง4.1-4.2) 6 6 โœ… 100%
Stream States (RFC 7540 ยง5.1) 7 7 โœ… 100%
DATA Frames (RFC 7540 ยง6.1) 3 3 โœ… 100%
HEADERS Frames (RFC 7540 ยง6.2) 4 4 โœ… 100%
PRIORITY Frames (RFC 7540 ยง6.3) 3 3 โœ… 100%
RST_STREAM Frames (RFC 7540 ยง6.4) 3 3 โœ… 100%
SETTINGS Frames (RFC 7540 ยง6.5) 9 9 โœ… 100%
HPACK Compression (RFC 7541) 20 20 โœ… 100%
Frame-Specific Edge Cases 51 51 โœ… 100%
Protocol Behavior & Semantics 54 54 โœ… 100%
Stream Lifecycle & Error Handling 28 28 โœ… 100%
๐Ÿ“Š TOTAL 192 192 โœ… 100%

For detailed test documentation and implementation details, see:

Installation

Add this to your application's shard.yml:

dependencies:
  h2o:
    github: nomadlabsinc/h2o
    branch: main

Then run:

shards install

Quick Start

require "h2o"

# Create a client
client = H2O::Client.new

# Make a simple GET request
response = client.get("https://httpbin.org/get")
puts response.status  # => 200
puts response.body    # => JSON response

# Make a POST request with body
headers = H2O::Headers.new
headers["content-type"] = "application/json"
body = %q({"key": "value"})

response = client.post("https://httpbin.org/post", body, headers)
puts response.status  # => 200

# Clean up
client.close

Basic Usage

Connection Pooling

client = H2O::Client.new(connection_pool_size: 20)

Request Timeouts

client = H2O::Client.new(timeout: 10.seconds)

Custom Headers

headers = H2O::Headers.new
headers["authorization"] = "Bearer your-token"
response = client.get("https://api.example.com/protected", headers)

HTTP Methods

client = H2O::Client.new

response = client.get("https://api.example.com/users")
response = client.post("https://api.example.com/users", body)
response = client.put("https://api.example.com/users/1", body)
response = client.delete("https://api.example.com/users/1")
response = client.head("https://api.example.com/users")
response = client.options("https://api.example.com/users")
response = client.patch("https://api.example.com/users/1", body)

Advanced Features

For detailed documentation on advanced features, see:

Contributing

  1. Fork it (https://github.com/nomadlabsinc/h2o/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Please ensure all tests pass and code is properly formatted before submitting.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

Acknowledgments

  • Crystal Language Team for the excellent language and standard library
  • HTTP/2 specification authors (RFC 7540, RFC 7541)
  • The Crystal community for inspiration and best practices
Repository

h2o

Owner
Statistic
  • 2
  • 0
  • 0
  • 1
  • 1
  • about 1 hour ago
  • June 4, 2025
License

MIT License

Links
Synced at

Thu, 03 Jul 2025 01:38:01 GMT

Languages