@@ -233,6 +233,12 @@ struct aws_http_make_request_options {
233
233
* See `aws_http_on_stream_complete_fn`.
234
234
*/
235
235
aws_http_on_stream_complete_fn * on_complete ;
236
+
237
+ /**
238
+ * When using HTTP/2, request body data will be provided over time. The stream will only be polled for writing
239
+ * when data has been supplied via `aws_http2_stream_write_data`
240
+ */
241
+ bool http2_use_manual_data_writes ;
236
242
};
237
243
238
244
struct aws_http_request_handler_options {
@@ -286,6 +292,21 @@ struct aws_http_request_handler_options {
286
292
aws_http_on_stream_complete_fn * on_complete ;
287
293
};
288
294
295
+ /**
296
+ * Invoked when the data stream of an outgoing HTTP write operation is no longer in use.
297
+ * This is always invoked on the HTTP connection's event-loop thread.
298
+ *
299
+ * @param stream HTTP-stream this write operation was submitted to.
300
+ * @param error_code If error_code is AWS_ERROR_SUCCESS (0), the data was successfully sent.
301
+ * Any other error_code indicates that the HTTP-stream is in the process of terminating.
302
+ * If the error_code is AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
303
+ * the stream's termination has nothing to do with this write operation.
304
+ * Any other non-zero error code indicates a problem with this particular write
305
+ * operation's data.
306
+ * @param user_data User data for this write operation.
307
+ */
308
+ typedef void aws_http_stream_write_complete_fn (struct aws_http_stream * stream , int error_code , void * user_data );
309
+
289
310
/**
290
311
* Invoked when the data of an outgoing HTTP/1.1 chunk is no longer in use.
291
312
* This is always invoked on the HTTP connection's event-loop thread.
@@ -298,7 +319,7 @@ struct aws_http_request_handler_options {
298
319
* Any other non-zero error code indicates a problem with this particular chunk's data.
299
320
* @param user_data User data for this chunk.
300
321
*/
301
- typedef void aws_http1_stream_write_chunk_complete_fn ( struct aws_http_stream * stream , int error_code , void * user_data ) ;
322
+ typedef aws_http_stream_write_complete_fn aws_http1_stream_write_chunk_complete_fn ;
302
323
303
324
/**
304
325
* HTTP/1.1 chunk extension for chunked encoding.
@@ -356,6 +377,50 @@ struct aws_http1_chunk_options {
356
377
void * user_data ;
357
378
};
358
379
380
+ /**
381
+ * Invoked when the data of an outgoing HTTP2 data frame is no longer in use.
382
+ * This is always invoked on the HTTP connection's event-loop thread.
383
+ *
384
+ * @param stream HTTP2-stream this write was submitted to.
385
+ * @param error_code If error_code is AWS_ERROR_SUCCESS (0), the data was successfully sent.
386
+ * Any other error_code indicates that the HTTP-stream is in the process of terminating.
387
+ * If the error_code is AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
388
+ * the stream's termination has nothing to do with this write.
389
+ * Any other non-zero error code indicates a problem with this particular write's data.
390
+ * @param user_data User data for this write.
391
+ */
392
+ typedef aws_http_stream_write_complete_fn aws_http2_stream_write_data_complete_fn ;
393
+
394
+ /**
395
+ * Encoding options for manual H2 data frame writes
396
+ */
397
+ struct aws_http2_stream_write_data_options {
398
+ /**
399
+ * The data to be sent.
400
+ * Optional.
401
+ * If not set, input stream with length 0 will be used.
402
+ */
403
+ struct aws_input_stream * data ;
404
+
405
+ /**
406
+ * Set true when it's the last chunk to be sent.
407
+ * After a write with end_stream, no more data write will be accepted.
408
+ */
409
+ bool end_stream ;
410
+
411
+ /**
412
+ * Invoked when the data stream is no longer in use, whether or not it was successfully sent.
413
+ * Optional.
414
+ * See `aws_http2_stream_write_data_complete_fn`.
415
+ */
416
+ aws_http2_stream_write_data_complete_fn * on_complete ;
417
+
418
+ /**
419
+ * User provided data passed to the on_complete callback on its invocation.
420
+ */
421
+ void * user_data ;
422
+ };
423
+
359
424
#define AWS_HTTP_REQUEST_HANDLER_OPTIONS_INIT \
360
425
{ .self_size = sizeof(struct aws_http_request_handler_options), }
361
426
@@ -728,9 +793,37 @@ AWS_HTTP_API int aws_http1_stream_write_chunk(
728
793
struct aws_http_stream * http1_stream ,
729
794
const struct aws_http1_chunk_options * options );
730
795
796
+ /**
797
+ * The stream must have specified `http2_use_manual_data_writes` during request creation.
798
+ * For client streams, activate() must be called before any frames are submitted.
799
+ * For server streams, the response headers must be submitted before any frames.
800
+ * A write with options that has end_stream set to be true will end the stream and prevent any further write.
801
+ *
802
+ * @return AWS_OP_SUCCESS if the write was queued
803
+ * AWS_OP_ERROR indicating the attempt raised an error code.
804
+ * AWS_ERROR_INVALID_STATE will be raised for invalid usage.
805
+ * AWS_ERROR_HTTP_STREAM_HAS_COMPLETED will be raised if the stream ended for reasons behind the scenes.
806
+ *
807
+ * Typical usage will be something like:
808
+ * options.http2_use_manual_data_writes = true;
809
+ * stream = aws_http_connection_make_request(connection, &options);
810
+ * aws_http_stream_activate(stream);
811
+ * ...
812
+ * struct aws_http2_stream_write_data_options write;
813
+ * aws_http2_stream_write_data(stream, &write);
814
+ * ...
815
+ * struct aws_http2_stream_write_data_options last_write;
816
+ * last_write.end_stream = true;
817
+ * aws_http2_stream_write_data(stream, &write);
818
+ * ...
819
+ * aws_http_stream_release(stream);
820
+ */
821
+ AWS_HTTP_API int aws_http2_stream_write_data (
822
+ struct aws_http_stream * http2_stream ,
823
+ const struct aws_http2_stream_write_data_options * options );
824
+
731
825
/**
732
826
* Add a list of headers to be added as trailing headers sent after the last chunk is sent.
733
- * The stream must have specified "chunked" in a "transfer-encoding" header. The stream should also have
734
827
* a "Trailer" header field which indicates the fields present in the trailer.
735
828
*
736
829
* Certain headers are forbidden in the trailer (e.g., Transfer-Encoding, Content-Length, Host). See RFC-7541
@@ -750,7 +843,6 @@ AWS_HTTP_API int aws_http1_stream_add_chunked_trailer(
750
843
const struct aws_http_headers * trailing_headers );
751
844
752
845
/**
753
- * Get the message's aws_http_headers.
754
846
*
755
847
* This datastructure has more functions for inspecting and modifying headers than
756
848
* are available on the aws_http_message datastructure.
0 commit comments