Skip to content

Unified write data API#552

Open
azkrishpy wants to merge 28 commits intomainfrom
unified-write-data-api
Open

Unified write data API#552
azkrishpy wants to merge 28 commits intomainfrom
unified-write-data-api

Conversation

@azkrishpy
Copy link
Contributor

@azkrishpy azkrishpy commented Feb 25, 2026

Issue #, if available:

Description of changes:
A new protocol-agnostic aws_http_stream_write_data() API that lets users write request body data the same way regardless of whether the connection is HTTP/1.1 or HTTP/2.

High level details of changes:
Public API:

  • New aws_http_stream_write_data() function that works for both H1 and H2
  • New use_manual_data_writes flag in request options (unified replacement for the H2-only http2_use_manual_data_writes)
  • Both old APIs (aws_http1_stream_write_chunk, aws_http2_stream_write_data) still work for backward compatibility

H1 Content-Length path:

  • User sets Content-Length header + use_manual_data_writes = true, no body stream
  • Each write_data call creates an aws_h1_data_write that gets queued and processed by the encoder
  • New encoder states (DATA_WRITE_NEXT, DATA_WRITE_BODY) handle reading from queued writes and tracking progress against Content-Length
  • Encoder validates total bytes match Content-Length when end_stream = true

H1 Chunked path:

  • User sets Transfer-Encoding: chunked header + use_manual_data_writes = true
  • write_data internally converts to write_chunk calls (same underlying mechanism as before)
  • User sends a zero-length write_data with end_stream = true to terminate (consistent with write_chunk behavior)

H2 path:

  • use_manual_data_writes now works for H2 (alongside the existing http2_use_manual_data_writes)
  • Internally routes through the same vtable->write_data as before — H2 implementation unchanged

Vtable unification:

  • Single write_data vtable entry replaces the old http2_write_data
  • H1 stream implements it (new), H2 stream implements it (renamed from existing)
  • aws_http2_stream_write_data() casts options and calls the same vtable entry

Elasticurl example:

  • Added --manual-write interactive mode demonstrating the API

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 85.33333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.75%. Comparing base (a9745ea) to head (f68f849).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
source/h1_stream.c 84.41% 12 Missing ⚠️
source/h1_encoder.c 83.33% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #552      +/-   ##
==========================================
+ Coverage   79.72%   79.75%   +0.02%     
==========================================
  Files          28       28              
  Lines       11894    12015     +121     
==========================================
+ Hits         9483     9583     +100     
- Misses       2411     2432      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@azkrishpy azkrishpy force-pushed the unified-write-data-api branch from c7b318c to af32dd9 Compare March 2, 2026 22:35

struct aws_h1_encoder_message encoder_message;
ASSERT_SUCCESS(aws_h1_encoder_message_init_from_request(&encoder_message, allocator, request, &chunk_list));
ASSERT_SUCCESS(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we switch to having encoder options instead of adding more parameters?

@azkrishpy azkrishpy marked this pull request as ready for review March 3, 2026 01:24
@azkrishpy azkrishpy requested a review from TingDaoK March 3, 2026 19:58
@azkrishpy azkrishpy requested a review from TingDaoK March 16, 2026 22:11
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.

3 participants