Skip to content

feat(http2): add HTTP/2 client support with TLS 1.3 and ALPN#109

Merged
kcenon merged 5 commits into
mainfrom
feature/http2-client-support
Nov 27, 2025
Merged

feat(http2): add HTTP/2 client support with TLS 1.3 and ALPN#109
kcenon merged 5 commits into
mainfrom
feature/http2-client-support

Conversation

@kcenon

@kcenon kcenon commented Nov 27, 2025

Copy link
Copy Markdown
Owner

Summary

  • Implement HTTP/2 client for modern web service communication (RFC 7540)
  • Add TLS 1.3 with ALPN negotiation ("h2") for secure HTTP/2 connections
  • Include comprehensive unit tests for the new client

Features

  • Full HTTP/2 protocol implementation
  • HPACK header compression (RFC 7541)
  • Stream multiplexing over single connection
  • Flow control with WINDOW_UPDATE frames
  • PING/PONG for connection keepalive
  • Graceful shutdown with GOAWAY frames
  • Async I/O with ASIO

API

class http2_client {
public:
    explicit http2_client(std::string_view client_id);
    
    auto connect(const std::string& host, unsigned short port = 443) -> VoidResult;
    auto disconnect() -> VoidResult;
    auto is_connected() const -> bool;
    
    auto get(const std::string& path, const std::vector<http_header>& headers = {}) -> Result<http2_response>;
    auto post(const std::string& path, const std::string& body, const std::vector<http_header>& headers = {}) -> Result<http2_response>;
    auto put(const std::string& path, const std::string& body, const std::vector<http_header>& headers = {}) -> Result<http2_response>;
    auto del(const std::string& path, const std::vector<http_header>& headers = {}) -> Result<http2_response>;
};

Files Changed

  • include/kcenon/network/protocols/http2/http2_client.h - Header file
  • src/protocols/http2/http2_client.cpp - Implementation
  • tests/test_http2_client.cpp - Unit tests
  • CMakeLists.txt - Build configuration
  • tests/CMakeLists.txt - Test configuration
  • TODO.md - Mark ticket as completed

Test plan

  • Unit tests pass for http2_response helper methods
  • Unit tests pass for http2_client construction and settings
  • Connection tests verify error handling for invalid hosts
  • Request tests verify proper error handling when not connected

Implement HTTP/2 client for modern web service communication.

Features:
- Full HTTP/2 protocol support (RFC 7540)
- TLS 1.3 with ALPN negotiation ("h2")
- HPACK header compression (RFC 7541)
- Stream multiplexing over single connection
- Flow control with WINDOW_UPDATE frames
- PING/PONG for connection keepalive
- Graceful shutdown with GOAWAY frames
- Async I/O with ASIO

API:
- connect(host, port) - Establish TLS connection with HTTP/2
- get/post/put/del - HTTP methods with response futures
- Configurable timeout and settings

Added:
- include/kcenon/network/protocols/http2/http2_client.h
- src/protocols/http2/http2_client.cpp
- tests/test_http2_client.cpp

Closes #3 (HTTP/2 Client Support)
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Fix compilation errors when BUILD_WITH_COMMON_SYSTEM is not defined.
The error() and error_void() helper functions require individual
parameters (code, message, source, details), not a simple_error object.

Changes:
- Extract error fields before passing to error<T>() in read_frame()
- Extract error fields before passing to error<T>() in send_request()
- Extract error fields before passing to error_void() in handle_headers_frame()
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Fix compilation errors in test_http2_client.cpp:
- Add namespace alias 'err' for network_system::error_codes to avoid
  conflict with network_system::protocols::http2::error_code enum
- Replace error_codes:: with err:: for all error code references
- Fix Result<T> access: use .value() instead of -> operator
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

HTTP/2 client requires TLS for ALPN negotiation with "h2" protocol.
Move http2_client.cpp to BUILD_TLS_SUPPORT conditional sources and
wrap http2_client tests with the same condition.

This fixes build failures on Windows where OpenSSL may not be
available in all build configurations.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

The http2_client.h header includes asio/ssl.hpp which requires
OpenSSL headers. Add OpenSSL::SSL and OpenSSL::Crypto to test
target link libraries.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

@kcenon kcenon merged commit c76f707 into main Nov 27, 2025
43 checks passed
@kcenon kcenon deleted the feature/http2-client-support branch November 27, 2025 04:39
kcenon added a commit that referenced this pull request Apr 13, 2026
* feat(http2): add HTTP/2 client support with TLS 1.3 and ALPN

Implement HTTP/2 client for modern web service communication.

Features:
- Full HTTP/2 protocol support (RFC 7540)
- TLS 1.3 with ALPN negotiation ("h2")
- HPACK header compression (RFC 7541)
- Stream multiplexing over single connection
- Flow control with WINDOW_UPDATE frames
- PING/PONG for connection keepalive
- Graceful shutdown with GOAWAY frames
- Async I/O with ASIO

API:
- connect(host, port) - Establish TLS connection with HTTP/2
- get/post/put/del - HTTP methods with response futures
- Configurable timeout and settings

Added:
- include/kcenon/network/protocols/http2/http2_client.h
- src/protocols/http2/http2_client.cpp
- tests/test_http2_client.cpp

Closes #3 (HTTP/2 Client Support)

* fix(http2): correct error propagation in http2_client

Fix compilation errors when BUILD_WITH_COMMON_SYSTEM is not defined.
The error() and error_void() helper functions require individual
parameters (code, message, source, details), not a simple_error object.

Changes:
- Extract error fields before passing to error<T>() in read_frame()
- Extract error fields before passing to error<T>() in send_request()
- Extract error fields before passing to error_void() in handle_headers_frame()

* fix(test): resolve namespace conflicts in http2_client tests

Fix compilation errors in test_http2_client.cpp:
- Add namespace alias 'err' for network_system::error_codes to avoid
  conflict with network_system::protocols::http2::error_code enum
- Replace error_codes:: with err:: for all error code references
- Fix Result<T> access: use .value() instead of -> operator

* fix(build): make http2_client conditional on BUILD_TLS_SUPPORT

HTTP/2 client requires TLS for ALPN negotiation with "h2" protocol.
Move http2_client.cpp to BUILD_TLS_SUPPORT conditional sources and
wrap http2_client tests with the same condition.

This fixes build failures on Windows where OpenSSL may not be
available in all build configurations.

* fix(test): add OpenSSL link to http2_client_test

The http2_client.h header includes asio/ssl.hpp which requires
OpenSSL headers. Add OpenSSL::SSL and OpenSSL::Crypto to test
target link libraries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant