h2o
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:
- H2SPEC Compliance Documentation - Complete test coverage and methodology
- Native Test Implementation - Crystal-native H2SPEC compliance tests with RFC section mapping
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:
- Circuit Breaker Documentation - Resilience patterns, failure handling, and monitoring
- API Reference - Complete API documentation and usage patterns
- Integration Guide - Advanced integration and configuration examples
Contributing
- Fork it (https://github.com/nomadlabsinc/h2o/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - 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
- Nomad Labs Inc. - creator and maintainer
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
h2o
- 2
- 0
- 0
- 1
- 1
- about 1 hour ago
- June 4, 2025
MIT License
Thu, 03 Jul 2025 01:38:01 GMT