Skip to content

aws-smithy-http-server - http/1 support#4373

Merged
drganjoo merged 35 commits intofeature/http-1.xfrom
fahadzub/http-1.x-server-runtime
Dec 2, 2025
Merged

aws-smithy-http-server - http/1 support#4373
drganjoo merged 35 commits intofeature/http-1.xfrom
fahadzub/http-1.x-server-runtime

Conversation

@drganjoo
Copy link
Contributor

This PR migrates aws-smithy-http-server from http@0.x/hyper@0.14 to http@1.x/hyper@1.x.

Background

This is the second PR in the HTTP 1.x migration series:

  1. ✅ Legacy crates PR - Added aws-smithy-legacy-http and aws-smithy-legacy-http-server for http@0.x support
  2. 👉 This PR - Upgrade aws-smithy-http-server to http@1.x/hyper@1.x
  3. 🔜 Codegen changes - Add http-1x flag and conditional dependency logic

Key Changes

1. Dependency Upgrades

  • http: 0.2.91.x
  • http-body: 0.4.51.0
  • hyper: 0.14.261.x (with server, http1, http2 features)
  • hyper-util: Added 0.1 for server utilities (server-auto, server-graceful, etc.)
  • http-body-util: Added 0.1 for body utilities
  • tower-http: 0.30.6
  • lambda_http: 0.8.40.17 (for AWS Lambda support)

Updated aws-smithy-types to use http-body-1-x feature instead of http-body-0-4-x.

2. New serve Module

Added a comprehensive serve module (inspired by axum::serve) that provides:

  • Simple server API: Ergonomic serve(listener, service) function
  • Flexible listeners: Listener trait supporting TCP, Unix sockets, and custom transports
  • Connection limiting: Built-in limit_connections() via ListenerExt
  • Graceful shutdown: Zero-cost when unused, opt-in with .with_graceful_shutdown()
  • Hyper customization: .configure_hyper() for protocol and performance tuning
  • Comprehensive docs: Examples, troubleshooting, and advanced patterns

Files: src/serve/mod.rs (794 lines), src/serve/listener.rs (269 lines)

3. API Updates Throughout

Updated all modules to work with http@1.x APIs:

  • body.rs: Enhanced to work with http-body@1.0 traits (+176 lines)
  • routing/lambda_handler.rs: Updated for lambda_http@0.17 (+299 lines)
  • layer/alb_health_check.rs: Adapted for new HTTP types (+150 lines)
  • protocol modules: Updated all protocol implementations (REST JSON, AWS JSON, REST XML, RPC v2 CBOR)
  • rejection/error types: Added implementations for http@1.x error types

4. Comprehensive Testing

  • serve_integration_test.rs: 812 lines of integration tests for the serve module
  • graceful_shutdown_test.rs: 211 lines testing graceful shutdown scenarios
  • Tests verify HTTP/1, HTTP/2, connection limits, graceful shutdown, and error handling

Migration Impact

Breaking Change: This updates the public API to use http@1.x types (http::Request, http::Response, etc.).

Users will need to:

  1. Update their dependencies to use http@1.x
  2. Use the new serve() API or update to hyper@1.x connection APIs
  3. Update any code working directly with HTTP types

Benefits

  • Modern ecosystem: Aligns with the latest Rust HTTP ecosystem
  • Better ergonomics: New serve module provides simpler server setup
  • Performance: Benefits from hyper@1.x performance improvements
  • Maintainability: No need to maintain compatibility with deprecated versions
  • Feature completeness: Graceful shutdown, connection limiting, and flexible configuration

Testing

  • ✅ Integration tests cover major scenarios
  • ✅ Graceful shutdown tested
  • ✅ All protocol implementations verified

Next Steps

The next PR will update the codegen to conditionally generate code that uses either:

  • aws-smithy-legacy-http-server (for http@0.x - default)
  • aws-smithy-http-server (for http@1.x - when http-1x flag enabled)

@drganjoo drganjoo requested a review from a team as a code owner October 31, 2025 22:00
@drganjoo drganjoo requested a review from a team as a code owner November 1, 2025 09:13
// The listener limits concurrent connections to 100.
// Once 100 connections are active, new connections will wait at the OS level
// until an existing connection completes.
let listener = TcpListener::bind("0.0.0.0:3000").await?.limit_connections(100);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh...I wonder if we want an extension trait here or something more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from ListenerExt imported at the top—happy to hear what you had in mind for making it more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, let's remove this example. Examples should focus specifically on demonstrating functionality that is related to aws-smithy-http-server rather than other types.

Comment on lines +6 to +9
#![cfg_attr(
not(feature = "request-id"),
allow(unused_imports, dead_code, unreachable_code)
)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can cfg out the entire example? Or can you not because its an example and not a module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep the example visible because users might try to run it without the feature flag. In that case, we print helpful guidance via eprintln!('cargo run --example request_id --features request-id'). Not everyone will know they need to enable the feature flag initially, so this provides better user experience.

@rcoh
Copy link
Collaborator

rcoh commented Nov 7, 2025

rust-runtime/cargo.lock is deleted which is presumably unintentional

@drganjoo drganjoo merged commit 53cd75e into feature/http-1.x Dec 2, 2025
34 of 48 checks passed
@drganjoo drganjoo deleted the fahadzub/http-1.x-server-runtime branch December 2, 2025 09:04
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.

2 participants