Debian Codegraph @

crt/aws-c-http/include/aws/http/request_response.h

raw symbols SCIP
1 #ifndef AWS_HTTP_REQUEST_RESPONSE_H
2 #define AWS_HTTP_REQUEST_RESPONSE_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/http/http.h>
10
11 #include <aws/io/future.h>
12
13 AWS_PUSH_SANE_WARNING_LEVEL
14
15 struct aws_http_connection;
16 struct aws_input_stream;
17
18 /**
19 * A stream exists for the duration of a request/response exchange.
20 * A client creates a stream to send a request and receive a response.
21 * A server creates a stream to receive a request and send a response.
22 * In http/2, a push-promise stream can be sent by a server and received by a client.
23 */
24 struct aws_http_stream;
25
26 /**
27 * Controls whether a header's strings may be compressed by encoding the index of
28 * strings in a cache, rather than encoding the literal string.
29 *
30 * This setting has no effect on HTTP/1.x connections.
31 * On HTTP/2 connections this controls HPACK behavior.
32 * See RFC-7541 Section 7.1 for security considerations.
33 */
34 enum aws_http_header_compression {
35 /**
36 * Compress header by encoding the cached index of its strings,
37 * or by updating the cache to contain these strings for future reference.
38 * Best for headers that are sent repeatedly.
39 * This is the default setting.
40 */
41 AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
42
43 /**
44 * Encode header strings literally.
45 * If an intermediary re-broadcasts the headers, it is permitted to use cache.
46 * Best for unique headers that are unlikely to repeat.
47 */
48 AWS_HTTP_HEADER_COMPRESSION_NO_CACHE,
49
50 /**
51 * Encode header strings literally and forbid all intermediaries from using
52 * cache when re-broadcasting.
53 * Best for header fields that are highly valuable or sensitive to recovery.
54 */
55 AWS_HTTP_HEADER_COMPRESSION_NO_FORWARD_CACHE,
56 };
57
58 /**
59 * A lightweight HTTP header struct.
60 * Note that the underlying strings are not owned by the byte cursors.
61 */
62 struct aws_http_header {
63 struct aws_byte_cursor name;
64 struct aws_byte_cursor value;
65
66 /* Controls whether the header's strings may be compressed via caching. */
67 enum aws_http_header_compression compression;
68 };
69
70 /**
71 * A transformable block of HTTP headers.
72 * Provides a nice API for getting/setting header names and values.
73 *
74 * All strings are copied and stored within this datastructure.
75 * The index of a given header may change any time headers are modified.
76 * When iterating headers, the following ordering rules apply:
77 *
78 * - Headers with the same name will always be in the same order, relative to one another.
79 * If "A: one" is added before "A: two", then "A: one" will always precede "A: two".
80 *
81 * - Headers with different names could be in any order, relative to one another.
82 * If "A: one" is seen before "B: bee" in one iteration, you might see "B: bee" before "A: one" on the next.
83 */
84 struct aws_http_headers;
85
86 /**
87 * Header block type.
88 * INFORMATIONAL: Header block for 1xx informational (interim) responses.
89 * MAIN: Main header block sent with request or response.
90 * TRAILING: Headers sent after the body of a request or response.
91 */
92 enum aws_http_header_block {
93 AWS_HTTP_HEADER_BLOCK_MAIN,
94 AWS_HTTP_HEADER_BLOCK_INFORMATIONAL,
95 AWS_HTTP_HEADER_BLOCK_TRAILING,
96 };
97
98 /**
99 * The definition for an outgoing HTTP request or response.
100 * The message may be transformed (ex: signing the request) before its data is eventually sent.
101 *
102 * The message keeps internal copies of its trivial strings (method, path, headers)
103 * but does NOT take ownership of its body stream.
104 *
105 * A language binding would likely present this as an HttpMessage base class with
106 * HttpRequest and HttpResponse subclasses.
107 */
108 struct aws_http_message;
109
110 /**
111 * Function to invoke when a message transformation completes.
112 * This function MUST be invoked or the application will soft-lock.
113 * `message` and `complete_ctx` must be the same pointers provided to the `aws_http_message_transform_fn`.
114 * `error_code` should should be AWS_ERROR_SUCCESS if transformation was successful,
115 * otherwise pass a different AWS_ERROR_X value.
116 */
117 typedef void(
118 aws_http_message_transform_complete_fn)(struct aws_http_message *message, int error_code, void *complete_ctx);
119
120 /**
121 * A function that may modify a request or response before it is sent.
122 * The transformation may be asynchronous or immediate.
123 * The user MUST invoke the `complete_fn` when transformation is complete or the application will soft-lock.
124 * When invoking the `complete_fn`, pass along the `message` and `complete_ctx` provided here and an error code.
125 * The error code should be AWS_ERROR_SUCCESS if transformation was successful,
126 * otherwise pass a different AWS_ERROR_X value.
127 */
128 typedef void(aws_http_message_transform_fn)(
129 struct aws_http_message *message,
130 void *user_data,
131 aws_http_message_transform_complete_fn *complete_fn,
132 void *complete_ctx);
133
134 /**
135 * Invoked repeatedly times as headers are received.
136 * At this point, aws_http_stream_get_incoming_response_status() can be called for the client.
137 * And aws_http_stream_get_incoming_request_method() and aws_http_stream_get_incoming_request_uri() can be called for
138 * the server.
139 * This is always invoked on the HTTP connection's event-loop thread.
140 *
141 * Return AWS_OP_SUCCESS to continue processing the stream.
142 * Return aws_raise_error(E) to indicate failure and cancel the stream.
143 * The error you raise will be reflected in the error_code passed to the on_complete callback.
144 */
145 typedef int(aws_http_on_incoming_headers_fn)(
146 struct aws_http_stream *stream,
147 enum aws_http_header_block header_block,
148 const struct aws_http_header *header_array,
149 size_t num_headers,
150 void *user_data);
151
152 /**
153 * Invoked when the incoming header block of this type(informational/main/trailing) has been completely read.
154 * This is always invoked on the HTTP connection's event-loop thread.
155 *
156 * Return AWS_OP_SUCCESS to continue processing the stream.
157 * Return aws_raise_error(E) to indicate failure and cancel the stream.
158 * The error you raise will be reflected in the error_code passed to the on_complete callback.
159 */
160 typedef int(aws_http_on_incoming_header_block_done_fn)(
161 struct aws_http_stream *stream,
162 enum aws_http_header_block header_block,
163 void *user_data);
164
165 /**
166 * Called repeatedly as body data is received.
167 * The data must be copied immediately if you wish to preserve it.
168 * This is always invoked on the HTTP connection's event-loop thread.
169 *
170 * Note that, if the connection is using manual_window_management then the window
171 * size has shrunk by the amount of body data received. If the window size
172 * reaches 0 no further data will be received. Increment the window size with
173 * aws_http_stream_update_window().
174 *
175 * Return AWS_OP_SUCCESS to continue processing the stream.
176 * Return aws_raise_error(E) to indicate failure and cancel the stream.
177 * The error you raise will be reflected in the error_code passed to the on_complete callback.
178 */
179 typedef int(
180 aws_http_on_incoming_body_fn)(struct aws_http_stream *stream, const struct aws_byte_cursor *data, void *user_data);
181
182 /**
183 * Invoked when request has been completely read.
184 * This is always invoked on the HTTP connection's event-loop thread.
185 *
186 * Return AWS_OP_SUCCESS to continue processing the stream.
187 * Return aws_raise_error(E) to indicate failure and cancel the stream.
188 * The error you raise will be reflected in the error_code passed to the on_complete callback.
189 */
190 typedef int(aws_http_on_incoming_request_done_fn)(struct aws_http_stream *stream, void *user_data);
191
192 /**
193 * Invoked when the remote peer sends END_STREAM on an HTTP/2 stream.
194 * This is always invoked on the HTTP connection's event-loop thread.
195 *
196 * **HTTP/2 ONLY** - This callback is only supported for HTTP/2 request.
197 *
198 * This callback is invoked when the remote peer finishes sending by setting the END_STREAM
199 * flag on the final HEADERS or DATA frame. This indicates that no more data will be received from the
200 * remote peer for this stream.
201 *
202 * Note: If the server sends RST_STREAM instead of END_STREAM, `on_remote_end_stream` will NOT fire,
203 * but `on_complete` will fire with an error code.
204 *
205 * @param stream The HTTP/2 stream
206 * @param user_data User data provided in aws_http_make_request_options
207 */
208 typedef void(aws_http2_on_remote_end_stream_fn)(struct aws_http_stream *stream, void *user_data);
209
210 /**
211 * Invoked when a request/response stream is complete, whether successful or unsuccessful
212 * This is always invoked on the HTTP connection's event-loop thread.
213 * This will not be invoked if the stream is never activated.
214 */
215 typedef void(aws_http_on_stream_complete_fn)(struct aws_http_stream *stream, int error_code, void *user_data);
216
217 /**
218 * Invoked when request/response stream destroy completely.
219 * This can be invoked within the same thead who release the refcount on http stream.
220 * This is invoked even if the stream is never activated.
221 */
222 typedef void(aws_http_on_stream_destroy_fn)(void *user_data);
223
224 /**
225 * Tracing metrics for aws_http_stream.
226 * Data maybe not be available if the data of stream was never sent/received before it completes.
227 */
228 struct aws_http_stream_metrics {
229 /* The time stamp when the request started to be encoded. -1 means data not available. Timestamp
230 * are from `aws_high_res_clock_get_ticks` */
231 int64_t send_start_timestamp_ns;
232 /* The time stamp when the request finished to be encoded. -1 means data not available.
233 * Timestamp are from `aws_high_res_clock_get_ticks` */
234 int64_t send_end_timestamp_ns;
235 /* The time duration for the request from start encoding to finish encoding (send_end_timestamp_ns -
236 * send_start_timestamp_ns). -1 means data not available. */
237 int64_t sending_duration_ns;
238
239 /* The time stamp when the response started to be received from the network channel. -1 means data not available.
240 * Timestamp are from `aws_high_res_clock_get_ticks` */
241 int64_t receive_start_timestamp_ns;
242 /* The time stamp when the response finished to be received from the network channel. -1 means data not available.
243 * Timestamp are from `aws_high_res_clock_get_ticks` */
244 int64_t receive_end_timestamp_ns;
245 /* The time duration for the request from start receiving to finish receiving. receive_end_timestamp_ns -
246 * receive_start_timestamp_ns. -1 means data not available. */
247 int64_t receiving_duration_ns;
248
249 /* The stream-id on the connection when this stream was activated. */
250 uint32_t stream_id;
251 };
252
253 /**
254 * Invoked right before request/response stream is complete to report the tracing metrics for aws_http_stream.
255 * This may be invoked synchronously when aws_http_stream_release() is called.
256 * This is invoked even if the stream is never activated.
257 * See `aws_http_stream_metrics` for details.
258 */
259 typedef void(aws_http_on_stream_metrics_fn)(
260 struct aws_http_stream *stream,
261 const struct aws_http_stream_metrics *metrics,
262 void *user_data);
263
264 /**
265 * Options for creating a stream which sends a request from the client and receives a response from the server.
266 */
267 struct aws_http_make_request_options {
268 /**
269 * The sizeof() this struct, used for versioning.
270 * Required.
271 */
272 size_t self_size;
273
274 /**
275 * Definition for outgoing request.
276 * Required.
277 * The request will be kept alive via refcounting until the request completes.
278 */
279 struct aws_http_message *request;
280
281 void *user_data;
282
283 /**
284 * Invoked repeatedly times as headers are received.
285 * Optional.
286 * See `aws_http_on_incoming_headers_fn`.
287 */
288 aws_http_on_incoming_headers_fn *on_response_headers;
289
290 /**
291 * Invoked when response header block has been completely read.
292 * Optional.
293 * See `aws_http_on_incoming_header_block_done_fn`.
294 */
295 aws_http_on_incoming_header_block_done_fn *on_response_header_block_done;
296
297 /**
298 * Invoked repeatedly as body data is received.
299 * Optional.
300 * See `aws_http_on_incoming_body_fn`.
301 */
302 aws_http_on_incoming_body_fn *on_response_body;
303
304 /**
305 * Invoked right before stream is complete, whether successful or unsuccessful
306 * Optional.
307 * See `aws_http_on_stream_metrics_fn`
308 */
309 aws_http_on_stream_metrics_fn *on_metrics;
310
311 /**
312 * Invoked when the remote peer sends END_STREAM on an HTTP/2 stream (HTTP/2 ONLY).
313 * Optional.
314 * See `aws_http2_on_remote_end_stream_fn`.
315 *
316 * This callback fires when the remote peer sends END_STREAM, which happens BEFORE `on_complete`.
317 * Ignored for HTTP/1.x connections.
318 */
319 aws_http2_on_remote_end_stream_fn *on_h2_remote_end_stream;
320
321 /**
322 * Invoked when request/response stream is complete, whether successful or unsuccessful
323 * Optional.
324 * See `aws_http_on_stream_complete_fn`.
325 */
326 aws_http_on_stream_complete_fn *on_complete;
327
328 /* Callback for when the request/response stream is completely destroyed. */
329 aws_http_on_stream_destroy_fn *on_destroy;
330
331 /**
332 * When true, request body data will be provided over time via `aws_http_stream_write_data()`.
333 * The stream will only be polled for writing when data has been supplied.
334 * When false (default), the entire request body is read from the input stream immediately.
335 *
336 * HTTP/1.1 requirements:
337 * - SHOULD have either `Content-Length` OR `Transfer-Encoding: chunked` header (but not both).
338 * Fails with AWS_ERROR_HTTP_INVALID_HEADER_FIELD if both are set.
339 * Transfer-Encoding: chunked header will be automatically added if neither header is set.
340 * - MUST NOT have a body stream set. Fails with AWS_ERROR_HTTP_INVALID_HEADER_FIELD otherwise.
341 * - With `Content-Length`: total bytes written must exactly match the declared length.
342 * Fails with AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT if data exceeds Content-Length,
343 * or if `end_stream` is set before enough data is written.
344 * - With `Transfer-Encoding: chunked`: no length validation, data sent as chunks.
345 *
346 * HTTP/2: No `Content-Length` or `Transfer-Encoding` header required. Data sent via DATA frames.
347 * Note: When this variable is set, we expect request to be ended with a data write with end_stream=true.
348 */
349 bool use_manual_data_writes;
350
351 /**
352 * This field will be DEPRECATED and removed in a future release.
353 * Use `use_manual_data_writes` instead, which works for both HTTP/1.1 and HTTP/2.
354 * When using HTTP/2, request body data will be provided over time. The stream will only be polled for writing
355 * when data has been supplied via `aws_http2_stream_write_data`.
356 */
357 bool http2_use_manual_data_writes;
358
359 /**
360 * Optional (ignored if 0).
361 * After a request is fully sent, if the server does not begin responding within N milliseconds, then fail with
362 * AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT.
363 * It override the connection level settings, when the request completes, the
364 * original monitoring options will be applied back to the connection.
365 * TODO: Only supported in HTTP/1.1 now, support it in HTTP/2
366 */
367 uint64_t response_first_byte_timeout_ms;
368 };
369
370 struct aws_http_request_handler_options {
371 /* Set to sizeof() this struct, used for versioning. */
372 size_t self_size;
373
374 /**
375 * Required.
376 */
377 struct aws_http_connection *server_connection;
378
379 /**
380 * user_data passed to callbacks.
381 * Optional.
382 */
383 void *user_data;
384
385 /**
386 * Invoked repeatedly times as headers are received.
387 * Optional.
388 * See `aws_http_on_incoming_headers_fn`.
389 */
390 aws_http_on_incoming_headers_fn *on_request_headers;
391
392 /**
393 * Invoked when the request header block has been completely read.
394 * Optional.
395 * See `aws_http_on_incoming_header_block_done_fn`.
396 */
397 aws_http_on_incoming_header_block_done_fn *on_request_header_block_done;
398
399 /**
400 * Invoked as body data is received.
401 * Optional.
402 * See `aws_http_on_incoming_body_fn`.
403 */
404 aws_http_on_incoming_body_fn *on_request_body;
405
406 /**
407 * Invoked when request has been completely read.
408 * Optional.
409 * See `aws_http_on_incoming_request_done_fn`.
410 */
411 aws_http_on_incoming_request_done_fn *on_request_done;
412
413 /**
414 * Invoked when request/response stream is complete, whether successful or unsuccessful
415 * Optional.
416 * See `aws_http_on_stream_complete_fn`.
417 */
418 aws_http_on_stream_complete_fn *on_complete;
419
420 /* Callback for when the request/response stream is completely destroyed. */
421 aws_http_on_stream_destroy_fn *on_destroy;
422 };
423
424 /**
425 * Invoked when the data stream of an outgoing HTTP write operation is no longer in use.
426 * This is always invoked on the HTTP connection's event-loop thread.
427 *
428 * @param stream HTTP-stream this write operation was submitted to.
429 * @param error_code If error_code is AWS_ERROR_SUCCESS (0), the data was successfully sent.
430 * Any other error_code indicates that the HTTP-stream is in the process of terminating.
431 * If the error_code is AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
432 * the stream's termination has nothing to do with this write operation.
433 * Any other non-zero error code indicates a problem with this particular write
434 * operation's data.
435 * @param user_data User data for this write operation.
436 */
437 typedef void aws_http_stream_write_complete_fn(struct aws_http_stream *stream, int error_code, void *user_data);
438
439 /**
440 * Invoked when the data of an outgoing HTTP/1.1 chunk is no longer in use.
441 * This is always invoked on the HTTP connection's event-loop thread.
442 *
443 * @param stream HTTP-stream this chunk was submitted to.
444 * @param error_code If error_code is AWS_ERROR_SUCCESS (0), the data was successfully sent.
445 * Any other error_code indicates that the HTTP-stream is in the process of terminating.
446 * If the error_code is AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
447 * the stream's termination has nothing to do with this chunk.
448 * Any other non-zero error code indicates a problem with this particular chunk's data.
449 * @param user_data User data for this chunk.
450 */
451 typedef aws_http_stream_write_complete_fn aws_http1_stream_write_chunk_complete_fn;
452
453 /**
454 * HTTP/1.1 chunk extension for chunked encoding.
455 * Note that the underlying strings are not owned by the byte cursors.
456 */
457 struct aws_http1_chunk_extension {
458 struct aws_byte_cursor key;
459 struct aws_byte_cursor value;
460 };
461
462 /**
463 * Encoding options for an HTTP/1.1 chunked transfer encoding chunk.
464 */
465 struct aws_http1_chunk_options {
466 /*
467 * The data stream to be sent in a single chunk.
468 * The aws_input_stream must remain valid until on_complete is invoked.
469 * May be NULL in the final chunk with size 0.
470 *
471 * Note that, for Transfer-Encodings other than "chunked", the data is
472 * expected to already have that encoding applied. For example, if
473 * "Transfer-Encoding: gzip, chunked" then the data from aws_input_stream
474 * should already be in gzip format.
475 */
476 struct aws_input_stream *chunk_data;
477
478 /*
479 * Size of the chunk_data input stream in bytes.
480 */
481 uint64_t chunk_data_size;
482
483 /**
484 * A pointer to an array of chunked extensions.
485 * The num_extensions must match the length of the array.
486 * This data is deep-copied by aws_http1_stream_write_chunk(),
487 * it does not need to remain valid until on_complete is invoked.
488 */
489 struct aws_http1_chunk_extension *extensions;
490
491 /**
492 * The number of elements defined in the extensions array.
493 */
494 size_t num_extensions;
495
496 /**
497 * Invoked when the chunk data is no longer in use, whether or not it was successfully sent.
498 * Optional.
499 * See `aws_http1_stream_write_chunk_complete_fn`.
500 */
501 aws_http1_stream_write_chunk_complete_fn *on_complete;
502
503 /**
504 * User provided data passed to the on_complete callback on its invocation.
505 */
506 void *user_data;
507 };
508
509 /**
510 * Invoked when the data of an outgoing HTTP2 data frame is no longer in use.
511 * This is always invoked on the HTTP connection's event-loop thread.
512 *
513 * @param stream HTTP2-stream this write was submitted to.
514 * @param error_code If error_code is AWS_ERROR_SUCCESS (0), the data was successfully sent.
515 * Any other error_code indicates that the HTTP-stream is in the process of terminating.
516 * If the error_code is AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
517 * the stream's termination has nothing to do with this write.
518 * Any other non-zero error code indicates a problem with this particular write's data.
519 * @param user_data User data for this write.
520 */
521 typedef aws_http_stream_write_complete_fn aws_http2_stream_write_data_complete_fn;
522
523 /**
524 * Common fields for write_data options structures.
525 * This macro allows protocol-specific options to share the same base fields.
526 */
527 #define AWS_HTTP_STREAM_WRITE_DATA_OPTIONS_FIELDS \
528 /** \
529 * The data to be sent. \
530 * Optional. May be NULL to write zero bytes. \
531 * If NULL and end_stream is false, the write is a no-op. \
532 * If NULL and end_stream is true, the stream is completed with zero bytes written. \
533 * With Content-Length, total bytes across all writes must match the declared length \
534 * or the stream fails with AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT. \
535 */ \
536 struct aws_input_stream *data; \
537 /** \
538 * Set true when it's the last data to be sent. \
539 * After a write with end_stream, no more data writes will be accepted \
540 * (AWS_ERROR_HTTP_MANUAL_WRITE_HAS_COMPLETED). \
541 */ \
542 bool end_stream; \
543 /** \
544 * Invoked when the data is no longer in use, whether or not it was successfully sent. \
545 * Optional. \
546 * See `aws_http_stream_write_complete_fn`. \
547 * Called with AWS_ERROR_SUCCESS if data was sent successfully. \
548 * Called with AWS_ERROR_HTTP_STREAM_HAS_COMPLETED if the stream was torn down \
549 * before this write could be processed. \
550 * Called with another error code if this write's data caused a problem. \
551 */ \
552 aws_http_stream_write_complete_fn *on_complete; \
553 /** \
554 * User provided data passed to the on_complete callback on its invocation. \
555 */ \
556 void *user_data;
557
558 /**
559 * Unified options for writing data to an HTTP stream.
560 * Works with both HTTP/1.1 and HTTP/2.
561 */
562 struct aws_http_stream_write_data_options {
563 AWS_HTTP_STREAM_WRITE_DATA_OPTIONS_FIELDS
564 };
565
566 /**
567 * Encoding options for manual H2 data frame writes
568 */
569 struct aws_http2_stream_write_data_options {
570 AWS_HTTP_STREAM_WRITE_DATA_OPTIONS_FIELDS
571 };
572
573 #define AWS_HTTP_REQUEST_HANDLER_OPTIONS_INIT \
574 { \
575 .self_size = sizeof(struct aws_http_request_handler_options), \
576 }
577
578 AWS_EXTERN_C_BEGIN
579
580 /**
581 * Return whether both names are equivalent.
582 * This is a case-insensitive string comparison.
583 *
584 * Example Matches:
585 * "Content-Length" == "content-length" // upper or lower case ok
586
587 * Example Mismatches:
588 * "Content-Length" != " Content-Length" // leading whitespace bad
589 */
590 AWS_HTTP_API
591 bool aws_http_header_name_eq(struct aws_byte_cursor name_a, struct aws_byte_cursor name_b);
592
593 /**
594 * Create a new headers object.
595 * The caller has a hold on the object and must call aws_http_headers_release() when they are done with it.
596 */
597 AWS_HTTP_API
598 struct aws_http_headers *aws_http_headers_new(struct aws_allocator *allocator);
599
600 /**
601 * Acquire a hold on the object, preventing it from being deleted until
602 * aws_http_headers_release() is called by all those with a hold on it.
603 */
604 AWS_HTTP_API
605 void aws_http_headers_acquire(struct aws_http_headers *headers);
606
607 /**
608 * Release a hold on the object.
609 * The object is deleted when all holds on it are released.
610 */
611 AWS_HTTP_API
612 void aws_http_headers_release(struct aws_http_headers *headers);
613
614 /**
615 * Add a header.
616 * The underlying strings are copied.
617 */
618 AWS_HTTP_API
619 int aws_http_headers_add_header(struct aws_http_headers *headers, const struct aws_http_header *header);
620
621 /**
622 * Add a header.
623 * The underlying strings are copied.
624 */
625 AWS_HTTP_API
626 int aws_http_headers_add(struct aws_http_headers *headers, struct aws_byte_cursor name, struct aws_byte_cursor value);
627
628 /**
629 * Add an array of headers.
630 * The underlying strings are copied.
631 */
632 AWS_HTTP_API
633 int aws_http_headers_add_array(struct aws_http_headers *headers, const struct aws_http_header *array, size_t count);
634
635 /**
636 * Set a header value.
637 * The header is added if necessary and any existing values for this name are removed.
638 * The underlying strings are copied.
639 */
640 AWS_HTTP_API
641 int aws_http_headers_set(struct aws_http_headers *headers, struct aws_byte_cursor name, struct aws_byte_cursor value);
642
643 /**
644 * Get the total number of headers.
645 */
646 AWS_HTTP_API
647 size_t aws_http_headers_count(const struct aws_http_headers *headers);
648
649 /**
650 * Get the header at the specified index.
651 * The index of a given header may change any time headers are modified.
652 * When iterating headers, the following ordering rules apply:
653 *
654 * - Headers with the same name will always be in the same order, relative to one another.
655 * If "A: one" is added before "A: two", then "A: one" will always precede "A: two".
656 *
657 * - Headers with different names could be in any order, relative to one another.
658 * If "A: one" is seen before "B: bee" in one iteration, you might see "B: bee" before "A: one" on the next.
659 *
660 * AWS_ERROR_INVALID_INDEX is raised if the index is invalid.
661 */
662 AWS_HTTP_API
663 int aws_http_headers_get_index(
664 const struct aws_http_headers *headers,
665 size_t index,
666 struct aws_http_header *out_header);
667
668 /**
669 *
670 * Get all values with this name, combined into one new aws_string that you are responsible for destroying.
671 * If there are multiple headers with this name, their values are appended with comma-separators.
672 * If there are no headers with this name, NULL is returned and AWS_ERROR_HTTP_HEADER_NOT_FOUND is raised.
673 */
674 AWS_HTTP_API
675 struct aws_string *aws_http_headers_get_all(const struct aws_http_headers *headers, struct aws_byte_cursor name);
676
677 /**
678 * Get the first value for this name, ignoring any additional values.
679 * AWS_ERROR_HTTP_HEADER_NOT_FOUND is raised if the name is not found.
680 */
681 AWS_HTTP_API
682 int aws_http_headers_get(
683 const struct aws_http_headers *headers,
684 struct aws_byte_cursor name,
685 struct aws_byte_cursor *out_value);
686
687 /**
688 * Test if header name exists or not in headers
689 */
690 AWS_HTTP_API
691 bool aws_http_headers_has(const struct aws_http_headers *headers, struct aws_byte_cursor name);
692
693 /**
694 * Remove all headers with this name.
695 * AWS_ERROR_HTTP_HEADER_NOT_FOUND is raised if no headers with this name are found.
696 */
697 AWS_HTTP_API
698 int aws_http_headers_erase(struct aws_http_headers *headers, struct aws_byte_cursor name);
699
700 /**
701 * Remove the first header found with this name and value.
702 * AWS_ERROR_HTTP_HEADER_NOT_FOUND is raised if no such header is found.
703 */
704 AWS_HTTP_API
705 int aws_http_headers_erase_value(
706 struct aws_http_headers *headers,
707 struct aws_byte_cursor name,
708 struct aws_byte_cursor value);
709
710 /**
711 * Remove the header at the specified index.
712 *
713 * AWS_ERROR_INVALID_INDEX is raised if the index is invalid.
714 */
715 AWS_HTTP_API
716 int aws_http_headers_erase_index(struct aws_http_headers *headers, size_t index);
717
718 /**
719 * Clear all headers.
720 */
721 AWS_HTTP_API
722 void aws_http_headers_clear(struct aws_http_headers *headers);
723
724 /**
725 * Get the `:method` value (HTTP/2 headers only).
726 */
727 AWS_HTTP_API
728 int aws_http2_headers_get_request_method(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_method);
729
730 /**
731 * Set `:method` (HTTP/2 headers only).
732 * The headers makes its own copy of the underlying string.
733 */
734 AWS_HTTP_API
735 int aws_http2_headers_set_request_method(struct aws_http_headers *h2_headers, struct aws_byte_cursor method);
736
737 /*
738 * Get the `:scheme` value (HTTP/2 headers only).
739 */
740 AWS_HTTP_API
741 int aws_http2_headers_get_request_scheme(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_scheme);
742
743 /**
744 * Set `:scheme` (request pseudo headers only).
745 * The pseudo headers makes its own copy of the underlying string.
746 */
747 AWS_HTTP_API
748 int aws_http2_headers_set_request_scheme(struct aws_http_headers *h2_headers, struct aws_byte_cursor scheme);
749
750 /*
751 * Get the `:authority` value (request pseudo headers only).
752 */
753 AWS_HTTP_API
754 int aws_http2_headers_get_request_authority(
755 const struct aws_http_headers *h2_headers,
756 struct aws_byte_cursor *out_authority);
757
758 /**
759 * Set `:authority` (request pseudo headers only).
760 * The pseudo headers makes its own copy of the underlying string.
761 */
762 AWS_HTTP_API
763 int aws_http2_headers_set_request_authority(struct aws_http_headers *h2_headers, struct aws_byte_cursor authority);
764
765 /*
766 * Get the `:path` value (request pseudo headers only).
767 */
768 AWS_HTTP_API
769 int aws_http2_headers_get_request_path(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_path);
770
771 /**
772 * Set `:path` (request pseudo headers only).
773 * The pseudo headers makes its own copy of the underlying string.
774 */
775 AWS_HTTP_API
776 int aws_http2_headers_set_request_path(struct aws_http_headers *h2_headers, struct aws_byte_cursor path);
777
778 /**
779 * Get `:status` (response pseudo headers only).
780 * If no status is set, AWS_ERROR_HTTP_DATA_NOT_AVAILABLE is raised.
781 */
782 AWS_HTTP_API
783 int aws_http2_headers_get_response_status(const struct aws_http_headers *h2_headers, int *out_status_code);
784
785 /**
786 * Set `:status` (response pseudo headers only).
787 */
788 AWS_HTTP_API
789 int aws_http2_headers_set_response_status(struct aws_http_headers *h2_headers, int status_code);
790
791 /**
792 * Create a new HTTP/1.1 request message.
793 * The message is blank, all properties (method, path, etc) must be set individually.
794 * If HTTP/1.1 message used in HTTP/2 connection, the transformation will be automatically applied.
795 * A HTTP/2 message will created and sent based on the HTTP/1.1 message.
796 *
797 * The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
798 */
799 AWS_HTTP_API
800 struct aws_http_message *aws_http_message_new_request(struct aws_allocator *allocator);
801
802 /**
803 * Like aws_http_message_new_request(), but uses existing aws_http_headers instead of creating a new one.
804 * Acquires a hold on the headers, and releases it when the request is destroyed.
805 */
806 AWS_HTTP_API
807 struct aws_http_message *aws_http_message_new_request_with_headers(
808 struct aws_allocator *allocator,
809 struct aws_http_headers *existing_headers);
810
811 /**
812 * Create a new HTTP/1.1 response message.
813 * The message is blank, all properties (status, headers, etc) must be set individually.
814 *
815 * The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
816 */
817 AWS_HTTP_API
818 struct aws_http_message *aws_http_message_new_response(struct aws_allocator *allocator);
819
820 /**
821 * Create a new HTTP/2 request message.
822 * pseudo headers need to be set from aws_http2_headers_set_request_* to the headers of the aws_http_message.
823 * Will be errored out if used in HTTP/1.1 connection.
824 *
825 * The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
826 */
827 AWS_HTTP_API
828 struct aws_http_message *aws_http2_message_new_request(struct aws_allocator *allocator);
829
830 /**
831 * Create a new HTTP/2 response message.
832 * pseudo headers need to be set from aws_http2_headers_set_response_status to the headers of the aws_http_message.
833 * Will be errored out if used in HTTP/1.1 connection.
834 *
835 * The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
836 */
837 AWS_HTTP_API
838 struct aws_http_message *aws_http2_message_new_response(struct aws_allocator *allocator);
839
840 /**
841 * Create an HTTP/2 message from HTTP/1.1 message.
842 * pseudo headers will be created from the context and added to the headers of new message.
843 * Normal headers will be copied to the headers of new message.
844 * Note:
845 * - if `host` exist, it will be removed and `:authority` will be added using the information.
846 * - `:scheme` always defaults to "https". To use a different scheme create the HTTP/2 message directly
847 */
848 AWS_HTTP_API
849 struct aws_http_message *aws_http2_message_new_from_http1(
850 struct aws_allocator *alloc,
851 const struct aws_http_message *http1_msg);
852
853 /**
854 * Acquire a hold on the object, preventing it from being deleted until
855 * aws_http_message_release() is called by all those with a hold on it.
856 *
857 * This function returns the passed in message (possibly NULL) so that acquire-and-assign can be done with a single
858 * statement.
859 */
860 AWS_HTTP_API
861 struct aws_http_message *aws_http_message_acquire(struct aws_http_message *message);
862
863 /**
864 * Release a hold on the object.
865 * The object is deleted when all holds on it are released.
866 *
867 * This function always returns NULL so that release-and-assign-NULL can be done with a single statement.
868 */
869 AWS_HTTP_API
870 struct aws_http_message *aws_http_message_release(struct aws_http_message *message);
871
872 /**
873 * Deprecated. This is equivalent to aws_http_message_release().
874 */
875 AWS_HTTP_API
876 void aws_http_message_destroy(struct aws_http_message *message);
877
878 AWS_HTTP_API
879 bool aws_http_message_is_request(const struct aws_http_message *message);
880
881 AWS_HTTP_API
882 bool aws_http_message_is_response(const struct aws_http_message *message);
883
884 /**
885 * Get the protocol version of the http message.
886 */
887 AWS_HTTP_API
888 enum aws_http_version aws_http_message_get_protocol_version(const struct aws_http_message *message);
889
890 /**
891 * Get the method (request messages only).
892 */
893 AWS_HTTP_API
894 int aws_http_message_get_request_method(
895 const struct aws_http_message *request_message,
896 struct aws_byte_cursor *out_method);
897
898 /**
899 * Set the method (request messages only).
900 * The request makes its own copy of the underlying string.
901 */
902 AWS_HTTP_API
903 int aws_http_message_set_request_method(struct aws_http_message *request_message, struct aws_byte_cursor method);
904
905 /*
906 * Get the path-and-query value (request messages only).
907 */
908 AWS_HTTP_API
909 int aws_http_message_get_request_path(const struct aws_http_message *request_message, struct aws_byte_cursor *out_path);
910
911 /**
912 * Set the path-and-query value (request messages only).
913 * The request makes its own copy of the underlying string.
914 */
915 AWS_HTTP_API
916 int aws_http_message_set_request_path(struct aws_http_message *request_message, struct aws_byte_cursor path);
917
918 /**
919 * Get the status code (response messages only).
920 * If no status is set, AWS_ERROR_HTTP_DATA_NOT_AVAILABLE is raised.
921 */
922 AWS_HTTP_API
923 int aws_http_message_get_response_status(const struct aws_http_message *response_message, int *out_status_code);
924
925 /**
926 * Set the status code (response messages only).
927 */
928 AWS_HTTP_API
929 int aws_http_message_set_response_status(struct aws_http_message *response_message, int status_code);
930
931 /**
932 * Get the body stream.
933 * Returns NULL if no body stream is set.
934 */
935 AWS_HTTP_API
936 struct aws_input_stream *aws_http_message_get_body_stream(const struct aws_http_message *message);
937
938 /**
939 * Set the body stream.
940 * NULL is an acceptable value for messages with no body.
941 * Note: The message does NOT take ownership of the body stream.
942 * The stream must not be destroyed until the message is complete.
943 */
944 AWS_HTTP_API
945 void aws_http_message_set_body_stream(struct aws_http_message *message, struct aws_input_stream *body_stream);
946
947 /**
948 * aws_future<aws_http_message*>
949 */
950 AWS_FUTURE_T_POINTER_WITH_RELEASE_DECLARATION(aws_future_http_message, struct aws_http_message, AWS_HTTP_API)
951
952 /**
953 * Submit a chunk of data to be sent on an HTTP/1.1 stream.
954 * The stream must have specified "chunked" in a "transfer-encoding" header,
955 * and the aws_http_message must NOT have any body stream set.
956 * For client streams, activate() must be called before any chunks are submitted.
957 * For server streams, the response must be submitted before any chunks.
958 * A final chunk with size 0 must be submitted to successfully complete the HTTP-stream.
959 *
960 * Returns AWS_OP_SUCCESS if the chunk has been submitted. The chunk's completion
961 * callback will be invoked when the HTTP-stream is done with the chunk data,
962 * whether or not it was successfully sent (see `aws_http1_stream_write_chunk_complete_fn`).
963 * The chunk data must remain valid until the completion callback is invoked.
964 *
965 * Returns AWS_OP_ERR and raises an error if the chunk could not be submitted.
966 * In this case, the chunk's completion callback will never be invoked.
967 * Note that it is always possible for the HTTP-stream to terminate unexpectedly
968 * prior to this call being made, in which case the error raised is
969 * AWS_ERROR_HTTP_STREAM_HAS_COMPLETED.
970 */
971 AWS_HTTP_API int aws_http1_stream_write_chunk(
972 struct aws_http_stream *http1_stream,
973 const struct aws_http1_chunk_options *options);
974
975 /**
976 * Write data to an HTTP stream in a protocol-agnostic way.
977 * Works with both HTTP/1.1 and HTTP/2.
978 *
979 * The stream must have specified `use_manual_data_writes` during request creation.
980 * For HTTP/1.1: The request must have either a Content-Length OR Transfer-Encoding: chunked header,
981 * but not both. Transfer-Encoding: chunked is automatically added if neither is set.
982 * The request must NOT have a body stream set.
983 *
984 * For client streams, activate() must be called before any data is written.
985 * For server streams, the response must be submitted before any data is written.
986 *
987 * If data is NULL and end_stream is false, the call is a no-op.
988 * If data is NULL and end_stream is true, the stream is completed with zero bytes written.
989 * A write with end_stream set to true will prevent any further writes.
990 *
991 * @return AWS_OP_SUCCESS if the write was queued successfully.
992 * AWS_OP_ERR indicating the attempt raised an error code:
993 * AWS_ERROR_HTTP_MANUAL_WRITE_NOT_ENABLED if use_manual_data_writes was not set.
994 * AWS_ERROR_HTTP_MANUAL_WRITE_HAS_COMPLETED if a previous write already set end_stream.
995 * AWS_ERROR_HTTP_STREAM_NOT_ACTIVATED if the stream has not been activated.
996 * AWS_ERROR_HTTP_STREAM_HAS_COMPLETED if the stream ended before this call.
997 */
998 AWS_HTTP_API int aws_http_stream_write_data(
999 struct aws_http_stream *stream,
1000 const struct aws_http_stream_write_data_options *options);
1001
1002 /**
1003 * This API will be DEPRECATED in favor of protocol agnostic `aws_http_stream_write_data` API.
1004 * The stream must have specified `http2_use_manual_data_writes` during request creation.
1005 * For client streams, activate() must be called before any frames are submitted.
1006 * For server streams, the response headers must be submitted before any frames.
1007 * A write with options that has end_stream set to be true will end the stream and prevent any further write.
1008 *
1009 * @return AWS_OP_SUCCESS if the write was queued
1010 * AWS_OP_ERROR indicating the attempt raised an error code.
1011 * AWS_ERROR_INVALID_STATE will be raised for invalid usage.
1012 * AWS_ERROR_HTTP_STREAM_HAS_COMPLETED will be raised if the stream ended for reasons behind the scenes.
1013 *
1014 * Typical usage will be something like:
1015 * options.http2_use_manual_data_writes = true;
1016 * stream = aws_http_connection_make_request(connection, &options);
1017 * aws_http_stream_activate(stream);
1018 * ...
1019 * struct aws_http2_stream_write_data_options write;
1020 * aws_http2_stream_write_data(stream, &write);
1021 * ...
1022 * struct aws_http2_stream_write_data_options last_write;
1023 * last_write.end_stream = true;
1024 * aws_http2_stream_write_data(stream, &write);
1025 * ...
1026 * aws_http_stream_release(stream);
1027 */
1028 AWS_HTTP_API int aws_http2_stream_write_data(
1029 struct aws_http_stream *http2_stream,
1030 const struct aws_http2_stream_write_data_options *options);
1031
1032 /**
1033 * Add a list of headers to be added as trailing headers sent after the last chunk is sent.
1034 * a "Trailer" header field which indicates the fields present in the trailer.
1035 *
1036 * Certain headers are forbidden in the trailer (e.g., Transfer-Encoding, Content-Length, Host). See RFC-7541
1037 * Section 4.1.2 for more details.
1038 *
1039 * For client streams, activate() must be called before any chunks are submitted.
1040 *
1041 * For server streams, the response must be submitted before the trailer can be added
1042 *
1043 * aws_http1_stream_add_chunked_trailer must be called before the final size 0 chunk, and at the moment can only
1044 * be called once, though this could change if need be.
1045 *
1046 * Returns AWS_OP_SUCCESS if the chunk has been submitted.
1047 */
1048 AWS_HTTP_API int aws_http1_stream_add_chunked_trailer(
1049 struct aws_http_stream *http1_stream,
1050 const struct aws_http_headers *trailing_headers);
1051
1052 /**
1053 *
1054 * This datastructure has more functions for inspecting and modifying headers than
1055 * are available on the aws_http_message datastructure.
1056 */
1057 AWS_HTTP_API
1058 struct aws_http_headers *aws_http_message_get_headers(const struct aws_http_message *message);
1059
1060 /**
1061 * Get the message's const aws_http_headers.
1062 */
1063 AWS_HTTP_API
1064 const struct aws_http_headers *aws_http_message_get_const_headers(const struct aws_http_message *message);
1065
1066 /**
1067 * Get the number of headers.
1068 */
1069 AWS_HTTP_API
1070 size_t aws_http_message_get_header_count(const struct aws_http_message *message);
1071
1072 /**
1073 * Get the header at the specified index.
1074 * This function cannot fail if a valid index is provided.
1075 * Otherwise, AWS_ERROR_INVALID_INDEX will be raised.
1076 *
1077 * The underlying strings are stored within the message.
1078 */
1079 AWS_HTTP_API
1080 int aws_http_message_get_header(
1081 const struct aws_http_message *message,
1082 struct aws_http_header *out_header,
1083 size_t index);
1084
1085 /**
1086 * Add a header to the end of the array.
1087 * The message makes its own copy of the underlying strings.
1088 */
1089 AWS_HTTP_API
1090 int aws_http_message_add_header(struct aws_http_message *message, struct aws_http_header header);
1091
1092 /**
1093 * Add an array of headers to the end of the header array.
1094 * The message makes its own copy of the underlying strings.
1095 *
1096 * This is a helper function useful when it's easier to define headers as a stack array, rather than calling add_header
1097 * repeatedly.
1098 */
1099 AWS_HTTP_API
1100 int aws_http_message_add_header_array(
1101 struct aws_http_message *message,
1102 const struct aws_http_header *headers,
1103 size_t num_headers);
1104
1105 /**
1106 * Remove the header at the specified index.
1107 * Headers after this index are all shifted back one position.
1108 *
1109 * This function cannot fail if a valid index is provided.
1110 * Otherwise, AWS_ERROR_INVALID_INDEX will be raised.
1111 */
1112 AWS_HTTP_API
1113 int aws_http_message_erase_header(struct aws_http_message *message, size_t index);
1114
1115 /**
1116 * Create a stream, with a client connection sending a request.
1117 * The request does not start sending automatically once the stream is created. You must call
1118 * aws_http_stream_activate to begin execution of the request.
1119 *
1120 * The `options` are copied during this call.
1121 *
1122 * Tip for language bindings: Do not bind the `options` struct. Use something more natural for your language,
1123 * such as Builder Pattern in Java, or Python's ability to take many optional arguments by name.
1124 *
1125 * Note: The header of the request will be sent as it is when the message to send protocol matches the protocol of the
1126 * connection.
1127 * - No `user-agent` will be added.
1128 * - No security check will be enforced. eg: `referer` header privacy should be enforced by the user-agent who adds the
1129 * header
1130 * - When HTTP/1 message sent on HTTP/2 connection, `aws_http2_message_new_from_http1` will be applied under the hood.
1131 * - When HTTP/2 message sent on HTTP/1 connection, no change will be made.
1132 */
1133 AWS_HTTP_API
1134 struct aws_http_stream *aws_http_connection_make_request(
1135 struct aws_http_connection *client_connection,
1136 const struct aws_http_make_request_options *options);
1137
1138 /**
1139 * Create a stream, with a server connection receiving and responding to a request.
1140 * This function can only be called from the `aws_http_on_incoming_request_fn` callback.
1141 * aws_http_stream_send_response() should be used to send a response.
1142 */
1143 AWS_HTTP_API
1144 struct aws_http_stream *aws_http_stream_new_server_request_handler(
1145 const struct aws_http_request_handler_options *options);
1146
1147 /**
1148 * Acquire refcount on the stream to prevent it from being cleaned up until it is released.
1149 */
1150 AWS_HTTP_API
1151 struct aws_http_stream *aws_http_stream_acquire(struct aws_http_stream *stream);
1152
1153 /**
1154 * Users must release the stream when they are done with it, or its memory will never be cleaned up.
1155 * This will not cancel the stream, its callbacks will still fire if the stream is still in progress.
1156 *
1157 * Tips for language bindings:
1158 * - Invoke this from the wrapper class's finalizer/destructor.
1159 * - Do not let the wrapper class be destroyed until on_complete() has fired.
1160 */
1161 AWS_HTTP_API
1162 void aws_http_stream_release(struct aws_http_stream *stream);
1163
1164 /**
1165 * Only used for client initiated streams (immediately following a call to aws_http_connection_make_request).
1166 *
1167 * Activates the request's outgoing stream processing.
1168 */
1169 AWS_HTTP_API int aws_http_stream_activate(struct aws_http_stream *stream);
1170
1171 AWS_HTTP_API
1172 struct aws_http_connection *aws_http_stream_get_connection(const struct aws_http_stream *stream);
1173
1174 /* Only valid in "request" streams, once response headers start arriving */
1175 AWS_HTTP_API
1176 int aws_http_stream_get_incoming_response_status(const struct aws_http_stream *stream, int *out_status);
1177
1178 /* Only valid in "request handler" streams, once request headers start arriving */
1179 AWS_HTTP_API
1180 int aws_http_stream_get_incoming_request_method(
1181 const struct aws_http_stream *stream,
1182 struct aws_byte_cursor *out_method);
1183
1184 AWS_HTTP_API
1185 int aws_http_stream_get_incoming_request_uri(const struct aws_http_stream *stream, struct aws_byte_cursor *out_uri);
1186
1187 /**
1188 * Send response (only callable from "request handler" streams)
1189 * The response object must stay alive at least until the stream's on_complete is called.
1190 */
1191 AWS_HTTP_API
1192 int aws_http_stream_send_response(struct aws_http_stream *stream, struct aws_http_message *response);
1193
1194 /**
1195 * Increment the stream's flow-control window to keep data flowing.
1196 *
1197 * If the connection was created with `manual_window_management` set true,
1198 * the flow-control window of each stream will shrink as body data is received
1199 * (headers, padding, and other metadata do not affect the window).
1200 * The connection's `initial_window_size` determines the starting size of each stream's window.
1201 * If a stream's flow-control window reaches 0, no further data will be received.
1202 *
1203 * If `manual_window_management` is false, this call will have no effect.
1204 * The connection maintains its flow-control windows such that
1205 * no back-pressure is applied and data arrives as fast as possible.
1206 *
1207 * For HTTP/2, the client control exactly when the WINDOW_UPDATE frame sent.
1208 * And client will make sure the WINDOW_UPDATE frame to be valid.
1209 * Check `stream_window_size_threshold_to_send_update` for details.
1210 */
1211 AWS_HTTP_API
1212 void aws_http_stream_update_window(struct aws_http_stream *stream, size_t increment_size);
1213
1214 /**
1215 * Gets the HTTP/2 id associated with a stream. Even h1 streams have an id (using the same allocation procedure
1216 * as http/2) for easier tracking purposes. For client streams, this will only be non-zero after a successful call
1217 * to aws_http_stream_activate()
1218 */
1219 AWS_HTTP_API
1220 uint32_t aws_http_stream_get_id(const struct aws_http_stream *stream);
1221
1222 /**
1223 * Cancel the stream in flight.
1224 * For HTTP/1.1 streams, it's equivalent to closing the connection.
1225 * For HTTP/2 streams, it's equivalent to calling reset on the stream with `AWS_HTTP2_ERR_CANCEL`.
1226 *
1227 * the stream will complete with the error code provided, unless the stream is
1228 * already completing for other reasons, or the stream is not activated,
1229 * in which case this call will have no impact.
1230 */
1231 AWS_HTTP_API
1232 void aws_http_stream_cancel(struct aws_http_stream *stream, int error_code);
1233 /**
1234 * Cancel the stream with default error code.
1235 * Equivalent to invoke aws_http_stream_cancel with AWS_ERROR_HTTP_STREAM_CANCELLED.
1236 */
1237 AWS_HTTP_API
1238 void aws_http_stream_cancel_default_error(struct aws_http_stream *stream);
1239
1240 /**
1241 * Reset the HTTP/2 stream (HTTP/2 only).
1242 * Note that if the stream closes before this async call is fully processed, the RST_STREAM frame will not be sent.
1243 *
1244 * @param http2_stream HTTP/2 stream.
1245 * @param http2_error aws_http2_error_code. Reason to reset the stream.
1246 */
1247 AWS_HTTP_API
1248 int aws_http2_stream_reset(struct aws_http_stream *http2_stream, uint32_t http2_error);
1249
1250 /**
1251 * Get the error code received in rst_stream.
1252 * Only valid if the stream has completed, and an RST_STREAM frame has received.
1253 *
1254 * @param http2_stream HTTP/2 stream.
1255 * @param out_http2_error Gets to set to HTTP/2 error code received in rst_stream.
1256 */
1257 AWS_HTTP_API
1258 int aws_http2_stream_get_received_reset_error_code(struct aws_http_stream *http2_stream, uint32_t *out_http2_error);
1259
1260 /**
1261 * Get the HTTP/2 error code sent in the RST_STREAM frame (HTTP/2 only).
1262 * Only valid if the stream has completed, and has sent an RST_STREAM frame.
1263 *
1264 * @param http2_stream HTTP/2 stream.
1265 * @param out_http2_error Gets to set to HTTP/2 error code sent in rst_stream.
1266 */
1267 AWS_HTTP_API
1268 int aws_http2_stream_get_sent_reset_error_code(struct aws_http_stream *http2_stream, uint32_t *out_http2_error);
1269
1270 AWS_EXTERN_C_END
1271 AWS_POP_SANE_WARNING_LEVEL
1272
1273 #endif /* AWS_HTTP_REQUEST_RESPONSE_H */