Debian Codegraph @

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

raw symbols SCIP
1 #ifndef AWS_HTTP_CONNECTION_H
2 #define AWS_HTTP_CONNECTION_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 AWS_PUSH_SANE_WARNING_LEVEL
12
13 struct aws_client_bootstrap;
14 struct aws_socket_options;
15 struct aws_socket_endpoint;
16 struct aws_tls_connection_options;
17 struct aws_http2_setting;
18 struct proxy_env_var_settings;
19
20 /**
21 * An HTTP connection.
22 * This type is used by both server-side and client-side connections.
23 * This type is also used by all supported versions of HTTP.
24 */
25 struct aws_http_connection;
26
27 /**
28 * Invoked when connect completes.
29 *
30 * If unsuccessful, error_code will be set, connection will be NULL,
31 * and the on_shutdown callback will never be invoked.
32 *
33 * If successful, error_code will be 0 and connection will be valid.
34 * The user is now responsible for the connection and must
35 * call aws_http_connection_release() when they are done with it.
36 *
37 * The connection uses one event-loop thread to do all its work.
38 * The thread invoking this callback will be the same thread that invokes all
39 * future callbacks for this connection and its streams.
40 */
41 typedef void(
42 aws_http_on_client_connection_setup_fn)(struct aws_http_connection *connection, int error_code, void *user_data);
43
44 /**
45 * Invoked when the connection has finished shutting down.
46 * Never invoked if on_setup failed.
47 * This is always invoked on connection's event-loop thread.
48 * Note that the connection is not completely done until on_shutdown has been invoked
49 * AND aws_http_connection_release() has been called.
50 */
51 typedef void(
52 aws_http_on_client_connection_shutdown_fn)(struct aws_http_connection *connection, int error_code, void *user_data);
53
54 /**
55 * Invoked when the HTTP/2 settings change is complete.
56 * If connection setup successfully this will always be invoked whether settings change successfully or unsuccessfully.
57 * If error_code is AWS_ERROR_SUCCESS (0), then the peer has acknowledged the settings and the change has been applied.
58 * If error_code is non-zero, then a connection error occurred before the settings could be fully acknowledged and
59 * applied. This is always invoked on the connection's event-loop thread.
60 */
61 typedef void(aws_http2_on_change_settings_complete_fn)(
62 struct aws_http_connection *http2_connection,
63 int error_code,
64 void *user_data);
65
66 /**
67 * Invoked when the HTTP/2 PING completes, whether peer has acknowledged it or not.
68 * If error_code is AWS_ERROR_SUCCESS (0), then the peer has acknowledged the PING and round_trip_time_ns will be the
69 * round trip time in nano seconds for the connection.
70 * If error_code is non-zero, then a connection error occurred before the PING get acknowledgment and round_trip_time_ns
71 * will be useless in this case.
72 */
73 typedef void(aws_http2_on_ping_complete_fn)(
74 struct aws_http_connection *http2_connection,
75 uint64_t round_trip_time_ns,
76 int error_code,
77 void *user_data);
78
79 /**
80 * Invoked when an HTTP/2 GOAWAY frame is received from peer.
81 * Implies that the peer has initiated shutdown, or encountered a serious error.
82 * Once a GOAWAY is received, no further streams may be created on this connection.
83 *
84 * @param http2_connection This HTTP/2 connection.
85 * @param last_stream_id ID of the last locally-initiated stream that peer will
86 * process. Any locally-initiated streams with a higher ID are ignored by
87 * peer, and are safe to retry on another connection.
88 * @param http2_error_code The HTTP/2 error code (RFC-7540 section 7) sent by peer.
89 * `enum aws_http2_error_code` lists official codes.
90 * @param debug_data The debug data sent by peer. It can be empty. (NOTE: this data is only valid for the lifetime of
91 * the callback. Make a deep copy if you wish to keep it longer.)
92 * @param user_data User-data passed to the callback.
93 */
94 typedef void(aws_http2_on_goaway_received_fn)(
95 struct aws_http_connection *http2_connection,
96 uint32_t last_stream_id,
97 uint32_t http2_error_code,
98 struct aws_byte_cursor debug_data,
99 void *user_data);
100
101 /**
102 * Invoked when new HTTP/2 settings from peer have been applied.
103 * Settings_array is the array of aws_http2_settings that contains all the settings we just changed in the order we
104 * applied (the order settings arrived). Num_settings is the number of elements in that array.
105 */
106 typedef void(aws_http2_on_remote_settings_change_fn)(
107 struct aws_http_connection *http2_connection,
108 const struct aws_http2_setting *settings_array,
109 size_t num_settings,
110 void *user_data);
111
112 /**
113 * Callback invoked on each statistics sample.
114 *
115 * connection_nonce is unique to each connection for disambiguation of each callback per connection.
116 */
117 typedef void(
118 aws_http_statistics_observer_fn)(size_t connection_nonce, const struct aws_array_list *stats_list, void *user_data);
119
120 /**
121 * Configuration options for connection monitoring
122 */
123 struct aws_http_connection_monitoring_options {
124
125 /**
126 * minimum required throughput of the connection. Throughput is only measured against the interval of time where
127 * there is actual io to perform. Read and write throughput are measured and checked independently of one another.
128 */
129 uint64_t minimum_throughput_bytes_per_second;
130
131 /*
132 * amount of time, in seconds, throughput is allowed to drop below the minimum before the connection is shut down
133 * as unhealthy.
134 */
135 uint32_t allowable_throughput_failure_interval_seconds;
136
137 /**
138 * invoked on each statistics publish by the underlying IO channel. Install this callback to receive the statistics
139 * for observation. This field is optional.
140 */
141 aws_http_statistics_observer_fn *statistics_observer_fn;
142
143 /**
144 * user_data to be passed to statistics_observer_fn.
145 */
146 void *statistics_observer_user_data;
147 };
148
149 /**
150 * Options specific to HTTP/1.x connections.
151 */
152 struct aws_http1_connection_options {
153 /**
154 * Optional
155 * Capacity in bytes of the HTTP/1 connection's read buffer.
156 * The buffer grows if the flow-control window of the incoming HTTP-stream
157 * reaches zero. If the buffer reaches capacity, no further socket data is
158 * read until the HTTP-stream's window opens again, allowing data to resume flowing.
159 *
160 * Ignored if `manual_window_management` is false.
161 * If zero is specified (the default) then a default capacity is chosen.
162 * A capacity that is too small may hinder throughput.
163 * A capacity that is too big may waste memory without helping throughput.
164 */
165 size_t read_buffer_capacity;
166 };
167
168 /**
169 * Options specific to HTTP/2 connections.
170 */
171 struct aws_http2_connection_options {
172 /**
173 * Optional
174 * The data of settings to change for initial settings.
175 * Note: each setting has its boundary. If settings_array is not set, num_settings has to be 0 to send an empty
176 * SETTINGS frame.
177 */
178 struct aws_http2_setting *initial_settings_array;
179
180 /**
181 * Required
182 * The num of settings to change (Length of the initial_settings_array).
183 */
184 size_t num_initial_settings;
185
186 /**
187 * Optional.
188 * Invoked when the HTTP/2 initial settings change is complete.
189 * If failed to setup the connection, this will not be invoked.
190 * Otherwise, this will be invoked, whether settings change successfully or unsuccessfully.
191 * See `aws_http2_on_change_settings_complete_fn`.
192 */
193 aws_http2_on_change_settings_complete_fn *on_initial_settings_completed;
194
195 /**
196 * Optional
197 * The max number of recently-closed streams to remember.
198 * Set it to zero to use the default setting, AWS_HTTP2_DEFAULT_MAX_CLOSED_STREAMS
199 *
200 * If the connection receives a frame for a closed stream,
201 * the frame will be ignored or cause a connection error,
202 * depending on the frame type and how the stream was closed.
203 * Remembering more streams reduces the chances that a late frame causes
204 * a connection error, but costs some memory.
205 */
206 size_t max_closed_streams;
207
208 /**
209 * Optional.
210 * Invoked when a valid GOAWAY frame received.
211 * See `aws_http2_on_goaway_received_fn`.
212 */
213 aws_http2_on_goaway_received_fn *on_goaway_received;
214
215 /**
216 * Optional.
217 * Invoked when new settings from peer have been applied.
218 * See `aws_http2_on_remote_settings_change_fn`.
219 */
220 aws_http2_on_remote_settings_change_fn *on_remote_settings_change;
221
222 /**
223 * Optional.
224 * Set to true to manually manage the flow-control window of whole HTTP/2 connection.
225 *
226 * If false, the connection will maintain its flow-control windows such that
227 * no back-pressure is applied and data arrives as fast as possible.
228 *
229 * If true, the flow-control window of the whole connection will shrink as body data
230 * is received (headers, padding, and other metadata do not affect the window) for every streams
231 * created on this connection.
232 * The initial connection flow-control window is 65,535.
233 * Once the connection's flow-control window reaches to 0, all the streams on the connection stop receiving any
234 * further data.
235 * The user must call aws_http2_connection_update_window() to increment the connection's
236 * window and keep data flowing.
237 * Note: the padding of data frame counts to the flow-control window.
238 * But, the client will always automatically update the window for padding even for manual window update.
239 */
240 bool conn_manual_window_management;
241
242 /**
243 * Optional.
244 * The threshold to send out a window update frame for the connection.
245 * Ignored if `conn_manual_window_management` is false.
246 * When the window_size_self for the connection is larger than the threshold,
247 * client will batch the window update and not send it out until the window_size_self
248 * drops below the threshold.
249 * Default to half of the initial connection flow-control window size, which is 32767.
250 */
251 uint32_t conn_window_size_threshold_to_send_update;
252 /**
253 * Optional.
254 * The threshold to send out a window update frame for the streams.
255 * Ignored if `manual_window_management` is false.
256 * When the window_size_self for the stream is larger than the threshold,
257 * client will batch the window update and not send it out until the window_size_self
258 * drops below the threshold.
259 * Default to half of the `initial_window_size`.
260 */
261 uint32_t stream_window_size_threshold_to_send_update;
262 };
263
264 /**
265 * Options for creating an HTTP client connection.
266 * Initialize with AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT to set default values.
267 */
268 struct aws_http_client_connection_options {
269 /**
270 * The sizeof() this struct, used for versioning.
271 * Set by AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT.
272 */
273 size_t self_size;
274
275 /**
276 * Required.
277 * Must outlive the connection.
278 */
279 struct aws_allocator *allocator;
280
281 /**
282 * Required.
283 * The connection keeps the bootstrap alive via ref-counting.
284 */
285 struct aws_client_bootstrap *bootstrap;
286
287 /**
288 * Required.
289 * aws_http_client_connect() makes a copy.
290 */
291 struct aws_byte_cursor host_name;
292
293 /**
294 * Required.
295 */
296 uint32_t port;
297
298 /**
299 * Required.
300 * aws_http_client_connect() makes a copy.
301 */
302 const struct aws_socket_options *socket_options;
303
304 /**
305 * Optional.
306 * aws_http_client_connect() deep-copies all contents,
307 * and keeps `aws_tls_ctx` alive via ref-counting.
308 */
309 const struct aws_tls_connection_options *tls_options;
310
311 /**
312 * Optional
313 * Configuration options related to http proxy usage.
314 * Relevant fields are copied internally.
315 */
316 const struct aws_http_proxy_options *proxy_options;
317
318 /*
319 * Optional.
320 * Configuration for using proxy from environment variable.
321 * Only works when proxy_options is not set.
322 */
323 const struct proxy_env_var_settings *proxy_ev_settings;
324
325 /**
326 * Optional
327 * Configuration options related to connection health monitoring
328 */
329 const struct aws_http_connection_monitoring_options *monitoring_options;
330
331 /**
332 * Optional (ignored if 0).
333 * After a request is fully sent, if the server does not begin responding within N milliseconds,
334 * then fail with AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT.
335 * This can be overridden per-request by aws_http_make_request_options.response_first_byte_timeout_ms.
336 * TODO: Only supported in HTTP/1.1 now, support it in HTTP/2
337 */
338 uint64_t response_first_byte_timeout_ms;
339
340 /**
341 * Set to true to manually manage the flow-control window of each stream.
342 *
343 * If false, the connection will maintain its flow-control windows such that
344 * no back-pressure is applied and data arrives as fast as possible.
345 *
346 * If true, the flow-control window of each stream will shrink as body data
347 * is received (headers, padding, and other metadata do not affect the window).
348 * `initial_window_size` determines the starting size of each stream's window.
349 *
350 * If a stream's flow-control window reaches 0, no further data will be received. The user must call
351 * aws_http_stream_update_window() to increment the stream's window and keep data flowing.
352 *
353 * If a HTTP/2 connection created, it will ONLY control the stream window management.
354 * Connection window management is controlled by `conn_manual_window_management`.
355 * `stream_window_size_threshold_to_send_update` controls when to send the WINDOW_UPDATE frame for the stream.
356 * Note: the padding of data frame counts to the flow-control window. But, the client will always automatically
357 * update the window for padding even for manual window update.
358 */
359 bool manual_window_management;
360
361 /**
362 * The starting size of each HTTP stream's flow-control window.
363 * Required if `manual_window_management` is true,
364 * ignored if `manual_window_management` is false.
365 *
366 * For HTTP/2 connection, this value will end up being one of the initial settings for the connection,
367 * `AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE`.
368 * The corresponding settings from `initial_settings_array` will override this value.
369 * Notes:
370 * - the setting value has the limitation of 2^31-1, otherwise the connection will be failed to be established with
371 * AWS_ERROR_INVALID_ARGUMENT.
372 * - when this set to 0, the initial window size will be set to 0, when `manual_window_management` is true.
373 */
374 size_t initial_window_size;
375
376 /**
377 * User data for callbacks
378 * Optional.
379 */
380 void *user_data;
381
382 /**
383 * Invoked when connect completes.
384 * Required.
385 * See `aws_http_on_client_connection_setup_fn`.
386 */
387 aws_http_on_client_connection_setup_fn *on_setup;
388
389 /**
390 * Invoked when the connection has finished shutting down.
391 * Never invoked if setup failed.
392 * Optional.
393 * See `aws_http_on_client_connection_shutdown_fn`.
394 */
395 aws_http_on_client_connection_shutdown_fn *on_shutdown;
396
397 /**
398 * Optional.
399 * When true, use prior knowledge to set up an HTTP/2 connection on a cleartext
400 * connection.
401 * When TLS is set and this is true, the connection will failed to be established,
402 * as prior knowledge only works for cleartext TLS.
403 * Refer to RFC7540 3.4
404 */
405 bool prior_knowledge_http2;
406
407 /**
408 * Optional.
409 * Pointer to the hash map containing the ALPN string to protocol to use.
410 * Hash from `struct aws_string *` to `enum aws_http_version`.
411 * If not set, only the predefined string `h2` and `http/1.1` will be recognized. Other negotiated ALPN string will
412 * result in a HTTP1/1 connection
413 * Note: Connection will keep a deep copy of the table and the strings.
414 */
415 struct aws_hash_table *alpn_string_map;
416
417 /**
418 * Options specific to HTTP/1.x connections.
419 * Optional.
420 * Ignored if connection is not HTTP/1.x.
421 * If connection is HTTP/1.x and options were not specified, default values are used.
422 */
423 const struct aws_http1_connection_options *http1_options;
424
425 /**
426 * Options specific to HTTP/2 connections.
427 * Optional.
428 * Ignored if connection is not HTTP/2.
429 * If connection is HTTP/2 and options were not specified, default values are used.
430 */
431 const struct aws_http2_connection_options *http2_options;
432
433 /**
434 * Optional.
435 * Requests the channel/connection be bound to a specific event loop rather than chosen sequentially from the
436 * event loop group associated with the client bootstrap.
437 */
438 struct aws_event_loop *requested_event_loop;
439
440 /**
441 * Optional
442 * Host resolution override that allows the user to override DNS behavior for this particular connection.
443 */
444 const struct aws_host_resolution_config *host_resolution_config;
445 };
446
447 /* Predefined settings identifiers (RFC-7540 6.5.2) */
448 enum aws_http2_settings_id {
449 AWS_HTTP2_SETTINGS_BEGIN_RANGE = 0x1, /* Beginning of known values */
450 AWS_HTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x1,
451 AWS_HTTP2_SETTINGS_ENABLE_PUSH = 0x2,
452 AWS_HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x3,
453 AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x4,
454 AWS_HTTP2_SETTINGS_MAX_FRAME_SIZE = 0x5,
455 AWS_HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x6,
456 AWS_HTTP2_SETTINGS_END_RANGE, /* End of known values */
457 };
458
459 /* A HTTP/2 setting and its value, used in SETTINGS frame */
460 struct aws_http2_setting {
461 enum aws_http2_settings_id id;
462 uint32_t value;
463 };
464
465 /**
466 * HTTP/2: Default value for max closed streams we will keep in memory.
467 */
468 #define AWS_HTTP2_DEFAULT_MAX_CLOSED_STREAMS (32)
469
470 /**
471 * HTTP/2: The size of payload for HTTP/2 PING frame.
472 */
473 #define AWS_HTTP2_PING_DATA_SIZE (8)
474
475 /**
476 * HTTP/2: The number of known settings.
477 */
478 #define AWS_HTTP2_SETTINGS_COUNT (6)
479
480 /**
481 * Initializes aws_http_client_connection_options with default values.
482 */
483 #define AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT \
484 { \
485 .self_size = sizeof(struct aws_http_client_connection_options), \
486 .initial_window_size = SIZE_MAX, \
487 }
488
489 AWS_EXTERN_C_BEGIN
490
491 /**
492 * Asynchronously establish a client connection.
493 * The on_setup callback is invoked when the operation has created a connection or failed.
494 */
495 AWS_HTTP_API
496 int aws_http_client_connect(const struct aws_http_client_connection_options *options);
497
498 /**
499 * Users must release the connection when they are done with it.
500 * The connection's memory cannot be reclaimed until this is done.
501 * If the connection was not already shutting down, it will be shut down.
502 *
503 * Users should always wait for the on_shutdown() callback to be called before releasing any data passed to the
504 * http_connection (Eg aws_tls_connection_options, aws_socket_options) otherwise there will be race conditions between
505 * http_connection shutdown tasks and memory release tasks, causing Segfaults.
506 */
507 AWS_HTTP_API
508 void aws_http_connection_release(struct aws_http_connection *connection);
509
510 /**
511 * Begin shutdown sequence of the connection if it hasn't already started. This will schedule shutdown tasks on the
512 * EventLoop that may send HTTP/TLS/TCP shutdown messages to peers if necessary, and will eventually cause internal
513 * connection memory to stop being accessed and on_shutdown() callback to be called.
514 *
515 * It's safe to call this function regardless of the connection state as long as you hold a reference to the connection.
516 */
517 AWS_HTTP_API
518 void aws_http_connection_close(struct aws_http_connection *connection);
519
520 /**
521 * Stop accepting new requests for the connection. It will NOT start the shutdown process for the connection. The
522 * requests that are already open can still wait to be completed, but new requests will fail to be created,
523 */
524 AWS_HTTP_API
525 void aws_http_connection_stop_new_requests(struct aws_http_connection *connection);
526
527 /**
528 * Returns true unless the connection is closed or closing.
529 */
530 AWS_HTTP_API
531 bool aws_http_connection_is_open(const struct aws_http_connection *connection);
532
533 /**
534 * Return whether the connection can make a new requests.
535 * If false, then a new connection must be established to make further requests.
536 */
537 AWS_HTTP_API
538 bool aws_http_connection_new_requests_allowed(const struct aws_http_connection *connection);
539
540 /**
541 * Returns true if this is a client connection.
542 */
543 AWS_HTTP_API
544 bool aws_http_connection_is_client(const struct aws_http_connection *connection);
545
546 AWS_HTTP_API
547 enum aws_http_version aws_http_connection_get_version(const struct aws_http_connection *connection);
548
549 /**
550 * Returns the channel hosting the HTTP connection.
551 * Do not expose this function to language bindings.
552 */
553 AWS_HTTP_API
554 struct aws_channel *aws_http_connection_get_channel(struct aws_http_connection *connection);
555
556 /**
557 * Returns the remote endpoint of the HTTP connection.
558 */
559 AWS_HTTP_API
560 const struct aws_socket_endpoint *aws_http_connection_get_remote_endpoint(const struct aws_http_connection *connection);
561
562 /**
563 * Initialize an map copied from the *src map, which maps `struct aws_string *` to `enum aws_http_version`.
564 */
565 AWS_HTTP_API
566 int aws_http_alpn_map_init_copy(
567 struct aws_allocator *allocator,
568 struct aws_hash_table *dest,
569 struct aws_hash_table *src);
570
571 /**
572 * Initialize an empty hash-table that maps `struct aws_string *` to `enum aws_http_version`.
573 * This map can used in aws_http_client_connections_options.alpn_string_map.
574 */
575 AWS_HTTP_API
576 int aws_http_alpn_map_init(struct aws_allocator *allocator, struct aws_hash_table *map);
577
578 /**
579 * Checks http proxy options for correctness
580 */
581 AWS_HTTP_API
582 int aws_http_options_validate_proxy_configuration(const struct aws_http_client_connection_options *options);
583
584 /**
585 * Send a SETTINGS frame (HTTP/2 only).
586 * SETTINGS will be applied locally when SETTINGS ACK is received from peer.
587 *
588 * @param http2_connection HTTP/2 connection.
589 * @param settings_array The array of settings to change. Note: each setting has its boundary.
590 * @param num_settings The num of settings to change in settings_array.
591 * @param on_completed Optional callback, see `aws_http2_on_change_settings_complete_fn`.
592 * @param user_data User-data pass to on_completed callback.
593 */
594 AWS_HTTP_API
595 int aws_http2_connection_change_settings(
596 struct aws_http_connection *http2_connection,
597 const struct aws_http2_setting *settings_array,
598 size_t num_settings,
599 aws_http2_on_change_settings_complete_fn *on_completed,
600 void *user_data);
601
602 /**
603 * Send a PING frame (HTTP/2 only).
604 * Round-trip-time is calculated when PING ACK is received from peer.
605 *
606 * @param http2_connection HTTP/2 connection.
607 * @param optional_opaque_data Optional payload for PING frame.
608 * Must be NULL, or exactly 8 bytes (AWS_HTTP2_PING_DATA_SIZE).
609 * If NULL, the 8 byte payload will be all zeroes.
610 * @param on_completed Optional callback, invoked when PING ACK is received from peer,
611 * or when a connection error prevents the PING ACK from being received.
612 * Callback always fires on the connection's event-loop thread.
613 * @param user_data User-data pass to on_completed callback.
614 */
615 AWS_HTTP_API
616 int aws_http2_connection_ping(
617 struct aws_http_connection *http2_connection,
618 const struct aws_byte_cursor *optional_opaque_data,
619 aws_http2_on_ping_complete_fn *on_completed,
620 void *user_data);
621
622 /**
623 * Get the local settings we are using to affect the decoding.
624 *
625 * @param http2_connection HTTP/2 connection.
626 * @param out_settings fixed size array of aws_http2_setting gets set to the local settings
627 */
628 AWS_HTTP_API
629 void aws_http2_connection_get_local_settings(
630 const struct aws_http_connection *http2_connection,
631 struct aws_http2_setting out_settings[AWS_HTTP2_SETTINGS_COUNT]);
632
633 /**
634 * Get the settings received from remote peer, which we are using to restricts the message to send.
635 *
636 * @param http2_connection HTTP/2 connection.
637 * @param out_settings fixed size array of aws_http2_setting gets set to the remote settings
638 */
639 AWS_HTTP_API
640 void aws_http2_connection_get_remote_settings(
641 const struct aws_http_connection *http2_connection,
642 struct aws_http2_setting out_settings[AWS_HTTP2_SETTINGS_COUNT]);
643
644 /**
645 * Send a custom GOAWAY frame (HTTP/2 only).
646 *
647 * Note that the connection automatically attempts to send a GOAWAY during
648 * shutdown (unless a GOAWAY with a valid Last-Stream-ID has already been sent).
649 *
650 * This call can be used to gracefully warn the peer of an impending shutdown
651 * (http2_error=0, allow_more_streams=true), or to customize the final GOAWAY
652 * frame that is sent by this connection.
653 *
654 * The other end may not receive the goaway, if the connection already closed.
655 *
656 * @param http2_connection HTTP/2 connection.
657 * @param http2_error The HTTP/2 error code (RFC-7540 section 7) to send.
658 * `enum aws_http2_error_code` lists official codes.
659 * @param allow_more_streams If true, new peer-initiated streams will continue
660 * to be acknowledged and the GOAWAY's Last-Stream-ID will be set to a max value.
661 * If false, new peer-initiated streams will be ignored and the GOAWAY's
662 * Last-Stream-ID will be set to the latest acknowledged stream.
663 * @param optional_debug_data Optional debug data to send. Size must not exceed 16KB.
664 */
665
666 AWS_HTTP_API
667 void aws_http2_connection_send_goaway(
668 struct aws_http_connection *http2_connection,
669 uint32_t http2_error,
670 bool allow_more_streams,
671 const struct aws_byte_cursor *optional_debug_data);
672
673 /**
674 * Get data about the latest GOAWAY frame sent to peer (HTTP/2 only).
675 * If no GOAWAY has been sent, AWS_ERROR_HTTP_DATA_NOT_AVAILABLE will be raised.
676 * Note that GOAWAY frames are typically sent automatically by the connection
677 * during shutdown.
678 *
679 * @param http2_connection HTTP/2 connection.
680 * @param out_http2_error Gets set to HTTP/2 error code sent in most recent GOAWAY.
681 * @param out_last_stream_id Gets set to Last-Stream-ID sent in most recent GOAWAY.
682 */
683 AWS_HTTP_API
684 int aws_http2_connection_get_sent_goaway(
685 struct aws_http_connection *http2_connection,
686 uint32_t *out_http2_error,
687 uint32_t *out_last_stream_id);
688
689 /**
690 * Get data about the latest GOAWAY frame received from peer (HTTP/2 only).
691 * If no GOAWAY has been received, or the GOAWAY payload is still in transmitting,
692 * AWS_ERROR_HTTP_DATA_NOT_AVAILABLE will be raised.
693 *
694 * @param http2_connection HTTP/2 connection.
695 * @param out_http2_error Gets set to HTTP/2 error code received in most recent GOAWAY.
696 * @param out_last_stream_id Gets set to Last-Stream-ID received in most recent GOAWAY.
697 */
698 AWS_HTTP_API
699 int aws_http2_connection_get_received_goaway(
700 struct aws_http_connection *http2_connection,
701 uint32_t *out_http2_error,
702 uint32_t *out_last_stream_id);
703
704 /**
705 * Increment the connection's flow-control window to keep data flowing (HTTP/2 only).
706 *
707 * If the connection was created with `conn_manual_window_management` set true,
708 * the flow-control window of the connection will shrink as body data is received for all the streams created on it.
709 * (headers, padding, and other metadata do not affect the window).
710 * The initial connection flow-control window is 65,535.
711 * Once the connection's flow-control window reaches to 0, all the streams on the connection stop receiving any further
712 * data.
713 *
714 * If `conn_manual_window_management` is false, this call will have no effect.
715 * The connection maintains its flow-control windows such that
716 * no back-pressure is applied and data arrives as fast as possible.
717 *
718 * If you are not connected, this call will have no effect.
719 *
720 * Crashes when the connection is not http2 connection.
721 * The limit of the Maximum Size is 2**31 - 1.
722 * And client will make sure the WINDOW_UPDATE frame to be valid.
723 *
724 * The client control exactly when the WINDOW_UPDATE frame sent.
725 * Check `conn_window_size_threshold_to_send_update` for details.
726 *
727 * @param http2_connection HTTP/2 connection.
728 * @param increment_size The size to increment for the connection's flow control window
729 */
730 AWS_HTTP_API
731 void aws_http2_connection_update_window(struct aws_http_connection *http2_connection, uint32_t increment_size);
732
733 AWS_EXTERN_C_END
734 AWS_POP_SANE_WARNING_LEVEL
735
736 #endif /* AWS_HTTP_CONNECTION_H */