Lesson 35 - Get Compute Auth Token Working
This commit is contained in:
@@ -0,0 +1,707 @@
|
||||
#ifndef AWS_HTTP_CONNECTION_H
|
||||
#define AWS_HTTP_CONNECTION_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_client_bootstrap;
|
||||
struct aws_socket_options;
|
||||
struct aws_socket_endpoint;
|
||||
struct aws_tls_connection_options;
|
||||
struct aws_http2_setting;
|
||||
struct proxy_env_var_settings;
|
||||
|
||||
/**
|
||||
* An HTTP connection.
|
||||
* This type is used by both server-side and client-side connections.
|
||||
* This type is also used by all supported versions of HTTP.
|
||||
*/
|
||||
struct aws_http_connection;
|
||||
|
||||
/**
|
||||
* Invoked when connect completes.
|
||||
*
|
||||
* If unsuccessful, error_code will be set, connection will be NULL,
|
||||
* and the on_shutdown callback will never be invoked.
|
||||
*
|
||||
* If successful, error_code will be 0 and connection will be valid.
|
||||
* The user is now responsible for the connection and must
|
||||
* call aws_http_connection_release() when they are done with it.
|
||||
*
|
||||
* The connection uses one event-loop thread to do all its work.
|
||||
* The thread invoking this callback will be the same thread that invokes all
|
||||
* future callbacks for this connection and its streams.
|
||||
*/
|
||||
typedef void(
|
||||
aws_http_on_client_connection_setup_fn)(struct aws_http_connection *connection, int error_code, void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked when the connection has finished shutting down.
|
||||
* Never invoked if on_setup failed.
|
||||
* This is always invoked on connection's event-loop thread.
|
||||
* Note that the connection is not completely done until on_shutdown has been invoked
|
||||
* AND aws_http_connection_release() has been called.
|
||||
*/
|
||||
typedef void(
|
||||
aws_http_on_client_connection_shutdown_fn)(struct aws_http_connection *connection, int error_code, void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked when the HTTP/2 settings change is complete.
|
||||
* If connection setup successfully this will always be invoked whether settings change successfully or unsuccessfully.
|
||||
* If error_code is AWS_ERROR_SUCCESS (0), then the peer has acknowledged the settings and the change has been applied.
|
||||
* If error_code is non-zero, then a connection error occurred before the settings could be fully acknowledged and
|
||||
* applied. This is always invoked on the connection's event-loop thread.
|
||||
*/
|
||||
typedef void(aws_http2_on_change_settings_complete_fn)(
|
||||
struct aws_http_connection *http2_connection,
|
||||
int error_code,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked when the HTTP/2 PING completes, whether peer has acknowledged it or not.
|
||||
* If error_code is AWS_ERROR_SUCCESS (0), then the peer has acknowledged the PING and round_trip_time_ns will be the
|
||||
* round trip time in nano seconds for the connection.
|
||||
* If error_code is non-zero, then a connection error occurred before the PING get acknowledgment and round_trip_time_ns
|
||||
* will be useless in this case.
|
||||
*/
|
||||
typedef void(aws_http2_on_ping_complete_fn)(
|
||||
struct aws_http_connection *http2_connection,
|
||||
uint64_t round_trip_time_ns,
|
||||
int error_code,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked when an HTTP/2 GOAWAY frame is received from peer.
|
||||
* Implies that the peer has initiated shutdown, or encountered a serious error.
|
||||
* Once a GOAWAY is received, no further streams may be created on this connection.
|
||||
*
|
||||
* @param http2_connection This HTTP/2 connection.
|
||||
* @param last_stream_id ID of the last locally-initiated stream that peer will
|
||||
* process. Any locally-initiated streams with a higher ID are ignored by
|
||||
* peer, and are safe to retry on another connection.
|
||||
* @param http2_error_code The HTTP/2 error code (RFC-7540 section 7) sent by peer.
|
||||
* `enum aws_http2_error_code` lists official codes.
|
||||
* @param debug_data The debug data sent by peer. It can be empty. (NOTE: this data is only valid for the lifetime of
|
||||
* the callback. Make a deep copy if you wish to keep it longer.)
|
||||
* @param user_data User-data passed to the callback.
|
||||
*/
|
||||
typedef void(aws_http2_on_goaway_received_fn)(
|
||||
struct aws_http_connection *http2_connection,
|
||||
uint32_t last_stream_id,
|
||||
uint32_t http2_error_code,
|
||||
struct aws_byte_cursor debug_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked when new HTTP/2 settings from peer have been applied.
|
||||
* Settings_array is the array of aws_http2_settings that contains all the settings we just changed in the order we
|
||||
* applied (the order settings arrived). Num_settings is the number of elements in that array.
|
||||
*/
|
||||
typedef void(aws_http2_on_remote_settings_change_fn)(
|
||||
struct aws_http_connection *http2_connection,
|
||||
const struct aws_http2_setting *settings_array,
|
||||
size_t num_settings,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Callback invoked on each statistics sample.
|
||||
*
|
||||
* connection_nonce is unique to each connection for disambiguation of each callback per connection.
|
||||
*/
|
||||
typedef void(
|
||||
aws_http_statistics_observer_fn)(size_t connection_nonce, const struct aws_array_list *stats_list, void *user_data);
|
||||
|
||||
/**
|
||||
* Configuration options for connection monitoring
|
||||
*/
|
||||
struct aws_http_connection_monitoring_options {
|
||||
|
||||
/**
|
||||
* minimum required throughput of the connection. Throughput is only measured against the interval of time where
|
||||
* there is actual io to perform. Read and write throughput are measured and checked independently of one another.
|
||||
*/
|
||||
uint64_t minimum_throughput_bytes_per_second;
|
||||
|
||||
/*
|
||||
* amount of time, in seconds, throughput is allowed to drop below the minimum before the connection is shut down
|
||||
* as unhealthy.
|
||||
*/
|
||||
uint32_t allowable_throughput_failure_interval_seconds;
|
||||
|
||||
/**
|
||||
* invoked on each statistics publish by the underlying IO channel. Install this callback to receive the statistics
|
||||
* for observation. This field is optional.
|
||||
*/
|
||||
aws_http_statistics_observer_fn *statistics_observer_fn;
|
||||
|
||||
/**
|
||||
* user_data to be passed to statistics_observer_fn.
|
||||
*/
|
||||
void *statistics_observer_user_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options specific to HTTP/1.x connections.
|
||||
*/
|
||||
struct aws_http1_connection_options {
|
||||
/**
|
||||
* Optional
|
||||
* Capacity in bytes of the HTTP/1 connection's read buffer.
|
||||
* The buffer grows if the flow-control window of the incoming HTTP-stream
|
||||
* reaches zero. If the buffer reaches capacity, no further socket data is
|
||||
* read until the HTTP-stream's window opens again, allowing data to resume flowing.
|
||||
*
|
||||
* Ignored if `manual_window_management` is false.
|
||||
* If zero is specified (the default) then a default capacity is chosen.
|
||||
* A capacity that is too small may hinder throughput.
|
||||
* A capacity that is too big may waste memory without helping throughput.
|
||||
*/
|
||||
size_t read_buffer_capacity;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options specific to HTTP/2 connections.
|
||||
*/
|
||||
struct aws_http2_connection_options {
|
||||
/**
|
||||
* Optional
|
||||
* The data of settings to change for initial settings.
|
||||
* Note: each setting has its boundary. If settings_array is not set, num_settings has to be 0 to send an empty
|
||||
* SETTINGS frame.
|
||||
*/
|
||||
struct aws_http2_setting *initial_settings_array;
|
||||
|
||||
/**
|
||||
* Required
|
||||
* The num of settings to change (Length of the initial_settings_array).
|
||||
*/
|
||||
size_t num_initial_settings;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Invoked when the HTTP/2 initial settings change is complete.
|
||||
* If failed to setup the connection, this will not be invoked.
|
||||
* Otherwise, this will be invoked, whether settings change successfully or unsuccessfully.
|
||||
* See `aws_http2_on_change_settings_complete_fn`.
|
||||
*/
|
||||
aws_http2_on_change_settings_complete_fn *on_initial_settings_completed;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* The max number of recently-closed streams to remember.
|
||||
* Set it to zero to use the default setting, AWS_HTTP2_DEFAULT_MAX_CLOSED_STREAMS
|
||||
*
|
||||
* If the connection receives a frame for a closed stream,
|
||||
* the frame will be ignored or cause a connection error,
|
||||
* depending on the frame type and how the stream was closed.
|
||||
* Remembering more streams reduces the chances that a late frame causes
|
||||
* a connection error, but costs some memory.
|
||||
*/
|
||||
size_t max_closed_streams;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Invoked when a valid GOAWAY frame received.
|
||||
* See `aws_http2_on_goaway_received_fn`.
|
||||
*/
|
||||
aws_http2_on_goaway_received_fn *on_goaway_received;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Invoked when new settings from peer have been applied.
|
||||
* See `aws_http2_on_remote_settings_change_fn`.
|
||||
*/
|
||||
aws_http2_on_remote_settings_change_fn *on_remote_settings_change;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Set to true to manually manage the flow-control window of whole HTTP/2 connection.
|
||||
*
|
||||
* If false, the connection will maintain its flow-control windows such that
|
||||
* no back-pressure is applied and data arrives as fast as possible.
|
||||
*
|
||||
* If true, the flow-control window of the whole connection will shrink as body data
|
||||
* is received (headers, padding, and other metadata do not affect the window) for every streams
|
||||
* created on this connection.
|
||||
* The initial connection flow-control window is 65,535.
|
||||
* Once the connection's flow-control window reaches to 0, all the streams on the connection stop receiving any
|
||||
* further data.
|
||||
* The user must call aws_http2_connection_update_window() to increment the connection's
|
||||
* window and keep data flowing.
|
||||
* Note: the padding of data frame counts to the flow-control window.
|
||||
* But, the client will always automatically update the window for padding even for manual window update.
|
||||
*/
|
||||
bool conn_manual_window_management;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for creating an HTTP client connection.
|
||||
* Initialize with AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT to set default values.
|
||||
*/
|
||||
struct aws_http_client_connection_options {
|
||||
/**
|
||||
* The sizeof() this struct, used for versioning.
|
||||
* Set by AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT.
|
||||
*/
|
||||
size_t self_size;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* Must outlive the connection.
|
||||
*/
|
||||
struct aws_allocator *allocator;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* The connection keeps the bootstrap alive via ref-counting.
|
||||
*/
|
||||
struct aws_client_bootstrap *bootstrap;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* aws_http_client_connect() makes a copy.
|
||||
*/
|
||||
struct aws_byte_cursor host_name;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
*/
|
||||
uint32_t port;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* aws_http_client_connect() makes a copy.
|
||||
*/
|
||||
const struct aws_socket_options *socket_options;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* aws_http_client_connect() deep-copies all contents,
|
||||
* and keeps `aws_tls_ctx` alive via ref-counting.
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_options;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Configuration options related to http proxy usage.
|
||||
* Relevant fields are copied internally.
|
||||
*/
|
||||
const struct aws_http_proxy_options *proxy_options;
|
||||
|
||||
/*
|
||||
* Optional.
|
||||
* Configuration for using proxy from environment variable.
|
||||
* Only works when proxy_options is not set.
|
||||
*/
|
||||
const struct proxy_env_var_settings *proxy_ev_settings;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Configuration options related to connection health monitoring
|
||||
*/
|
||||
const struct aws_http_connection_monitoring_options *monitoring_options;
|
||||
|
||||
/**
|
||||
* Optional (ignored if 0).
|
||||
* After a request is fully sent, if the server does not begin responding within N milliseconds,
|
||||
* then fail with AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT.
|
||||
* This can be overridden per-request by aws_http_make_request_options.response_first_byte_timeout_ms.
|
||||
* TODO: Only supported in HTTP/1.1 now, support it in HTTP/2
|
||||
*/
|
||||
uint64_t response_first_byte_timeout_ms;
|
||||
|
||||
/**
|
||||
* Set to true to manually manage the flow-control window of each stream.
|
||||
*
|
||||
* If false, the connection will maintain its flow-control windows such that
|
||||
* no back-pressure is applied and data arrives as fast as possible.
|
||||
*
|
||||
* If true, the flow-control window of each stream will shrink as body data
|
||||
* is received (headers, padding, and other metadata do not affect the window).
|
||||
* `initial_window_size` determines the starting size of each stream's window for HTTP/1 stream, while HTTP/2 stream
|
||||
* will use the settings AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE to inform the other side about read back pressure
|
||||
*
|
||||
* If a stream's flow-control window reaches 0, no further data will be received. The user must call
|
||||
* aws_http_stream_update_window() to increment the stream's window and keep data flowing.
|
||||
*
|
||||
* If a HTTP/2 connection created, it will ONLY control the stream window
|
||||
* management. Connection window management is controlled by
|
||||
* conn_manual_window_management. Note: the padding of data frame counts to the flow-control window.
|
||||
* But, the client will always automatically update the window for padding even for manual window update.
|
||||
*/
|
||||
bool manual_window_management;
|
||||
|
||||
/**
|
||||
* The starting size of each HTTP stream's flow-control window for HTTP/1 connection.
|
||||
* Required if `manual_window_management` is true,
|
||||
* ignored if `manual_window_management` is false.
|
||||
*
|
||||
* Always ignored when HTTP/2 connection created. The initial window size is controlled by the settings,
|
||||
* `AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE`
|
||||
*/
|
||||
size_t initial_window_size;
|
||||
|
||||
/**
|
||||
* User data for callbacks
|
||||
* Optional.
|
||||
*/
|
||||
void *user_data;
|
||||
|
||||
/**
|
||||
* Invoked when connect completes.
|
||||
* Required.
|
||||
* See `aws_http_on_client_connection_setup_fn`.
|
||||
*/
|
||||
aws_http_on_client_connection_setup_fn *on_setup;
|
||||
|
||||
/**
|
||||
* Invoked when the connection has finished shutting down.
|
||||
* Never invoked if setup failed.
|
||||
* Optional.
|
||||
* See `aws_http_on_client_connection_shutdown_fn`.
|
||||
*/
|
||||
aws_http_on_client_connection_shutdown_fn *on_shutdown;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* When true, use prior knowledge to set up an HTTP/2 connection on a cleartext
|
||||
* connection.
|
||||
* When TLS is set and this is true, the connection will failed to be established,
|
||||
* as prior knowledge only works for cleartext TLS.
|
||||
* Refer to RFC7540 3.4
|
||||
*/
|
||||
bool prior_knowledge_http2;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Pointer to the hash map containing the ALPN string to protocol to use.
|
||||
* Hash from `struct aws_string *` to `enum aws_http_version`.
|
||||
* If not set, only the predefined string `h2` and `http/1.1` will be recognized. Other negotiated ALPN string will
|
||||
* result in a HTTP1/1 connection
|
||||
* Note: Connection will keep a deep copy of the table and the strings.
|
||||
*/
|
||||
struct aws_hash_table *alpn_string_map;
|
||||
|
||||
/**
|
||||
* Options specific to HTTP/1.x connections.
|
||||
* Optional.
|
||||
* Ignored if connection is not HTTP/1.x.
|
||||
* If connection is HTTP/1.x and options were not specified, default values are used.
|
||||
*/
|
||||
const struct aws_http1_connection_options *http1_options;
|
||||
|
||||
/**
|
||||
* Options specific to HTTP/2 connections.
|
||||
* Optional.
|
||||
* Ignored if connection is not HTTP/2.
|
||||
* If connection is HTTP/2 and options were not specified, default values are used.
|
||||
*/
|
||||
const struct aws_http2_connection_options *http2_options;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Requests the channel/connection be bound to a specific event loop rather than chosen sequentially from the
|
||||
* event loop group associated with the client bootstrap.
|
||||
*/
|
||||
struct aws_event_loop *requested_event_loop;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Host resolution override that allows the user to override DNS behavior for this particular connection.
|
||||
*/
|
||||
const struct aws_host_resolution_config *host_resolution_config;
|
||||
};
|
||||
|
||||
/* Predefined settings identifiers (RFC-7540 6.5.2) */
|
||||
enum aws_http2_settings_id {
|
||||
AWS_HTTP2_SETTINGS_BEGIN_RANGE = 0x1, /* Beginning of known values */
|
||||
AWS_HTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x1,
|
||||
AWS_HTTP2_SETTINGS_ENABLE_PUSH = 0x2,
|
||||
AWS_HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x3,
|
||||
AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x4,
|
||||
AWS_HTTP2_SETTINGS_MAX_FRAME_SIZE = 0x5,
|
||||
AWS_HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x6,
|
||||
AWS_HTTP2_SETTINGS_END_RANGE, /* End of known values */
|
||||
};
|
||||
|
||||
/* A HTTP/2 setting and its value, used in SETTINGS frame */
|
||||
struct aws_http2_setting {
|
||||
enum aws_http2_settings_id id;
|
||||
uint32_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
* HTTP/2: Default value for max closed streams we will keep in memory.
|
||||
*/
|
||||
#define AWS_HTTP2_DEFAULT_MAX_CLOSED_STREAMS (32)
|
||||
|
||||
/**
|
||||
* HTTP/2: The size of payload for HTTP/2 PING frame.
|
||||
*/
|
||||
#define AWS_HTTP2_PING_DATA_SIZE (8)
|
||||
|
||||
/**
|
||||
* HTTP/2: The number of known settings.
|
||||
*/
|
||||
#define AWS_HTTP2_SETTINGS_COUNT (6)
|
||||
|
||||
/**
|
||||
* Initializes aws_http_client_connection_options with default values.
|
||||
*/
|
||||
#define AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT \
|
||||
{ \
|
||||
.self_size = sizeof(struct aws_http_client_connection_options), \
|
||||
.initial_window_size = SIZE_MAX, \
|
||||
}
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Asynchronously establish a client connection.
|
||||
* The on_setup callback is invoked when the operation has created a connection or failed.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_client_connect(const struct aws_http_client_connection_options *options);
|
||||
|
||||
/**
|
||||
* Users must release the connection when they are done with it.
|
||||
* The connection's memory cannot be reclaimed until this is done.
|
||||
* If the connection was not already shutting down, it will be shut down.
|
||||
*
|
||||
* Users should always wait for the on_shutdown() callback to be called before releasing any data passed to the
|
||||
* http_connection (Eg aws_tls_connection_options, aws_socket_options) otherwise there will be race conditions between
|
||||
* http_connection shutdown tasks and memory release tasks, causing Segfaults.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_release(struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Begin shutdown sequence of the connection if it hasn't already started. This will schedule shutdown tasks on the
|
||||
* EventLoop that may send HTTP/TLS/TCP shutdown messages to peers if necessary, and will eventually cause internal
|
||||
* connection memory to stop being accessed and on_shutdown() callback to be called.
|
||||
*
|
||||
* It's safe to call this function regardless of the connection state as long as you hold a reference to the connection.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_close(struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Stop accepting new requests for the connection. It will NOT start the shutdown process for the connection. The
|
||||
* requests that are already open can still wait to be completed, but new requests will fail to be created,
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_stop_new_requests(struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Returns true unless the connection is closed or closing.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
bool aws_http_connection_is_open(const struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Return whether the connection can make a new requests.
|
||||
* If false, then a new connection must be established to make further requests.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
bool aws_http_connection_new_requests_allowed(const struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Returns true if this is a client connection.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
bool aws_http_connection_is_client(const struct aws_http_connection *connection);
|
||||
|
||||
AWS_HTTP_API
|
||||
enum aws_http_version aws_http_connection_get_version(const struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Returns the channel hosting the HTTP connection.
|
||||
* Do not expose this function to language bindings.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_channel *aws_http_connection_get_channel(struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Returns the remote endpoint of the HTTP connection.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
const struct aws_socket_endpoint *aws_http_connection_get_remote_endpoint(const struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Initialize an map copied from the *src map, which maps `struct aws_string *` to `enum aws_http_version`.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_alpn_map_init_copy(
|
||||
struct aws_allocator *allocator,
|
||||
struct aws_hash_table *dest,
|
||||
struct aws_hash_table *src);
|
||||
|
||||
/**
|
||||
* Initialize an empty hash-table that maps `struct aws_string *` to `enum aws_http_version`.
|
||||
* This map can used in aws_http_client_connections_options.alpn_string_map.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_alpn_map_init(struct aws_allocator *allocator, struct aws_hash_table *map);
|
||||
|
||||
/**
|
||||
* Checks http proxy options for correctness
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_options_validate_proxy_configuration(const struct aws_http_client_connection_options *options);
|
||||
|
||||
/**
|
||||
* Send a SETTINGS frame (HTTP/2 only).
|
||||
* SETTINGS will be applied locally when SETTINGS ACK is received from peer.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param settings_array The array of settings to change. Note: each setting has its boundary.
|
||||
* @param num_settings The num of settings to change in settings_array.
|
||||
* @param on_completed Optional callback, see `aws_http2_on_change_settings_complete_fn`.
|
||||
* @param user_data User-data pass to on_completed callback.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http2_connection_change_settings(
|
||||
struct aws_http_connection *http2_connection,
|
||||
const struct aws_http2_setting *settings_array,
|
||||
size_t num_settings,
|
||||
aws_http2_on_change_settings_complete_fn *on_completed,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Send a PING frame (HTTP/2 only).
|
||||
* Round-trip-time is calculated when PING ACK is received from peer.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param optional_opaque_data Optional payload for PING frame.
|
||||
* Must be NULL, or exactly 8 bytes (AWS_HTTP2_PING_DATA_SIZE).
|
||||
* If NULL, the 8 byte payload will be all zeroes.
|
||||
* @param on_completed Optional callback, invoked when PING ACK is received from peer,
|
||||
* or when a connection error prevents the PING ACK from being received.
|
||||
* Callback always fires on the connection's event-loop thread.
|
||||
* @param user_data User-data pass to on_completed callback.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http2_connection_ping(
|
||||
struct aws_http_connection *http2_connection,
|
||||
const struct aws_byte_cursor *optional_opaque_data,
|
||||
aws_http2_on_ping_complete_fn *on_completed,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Get the local settings we are using to affect the decoding.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param out_settings fixed size array of aws_http2_setting gets set to the local settings
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http2_connection_get_local_settings(
|
||||
const struct aws_http_connection *http2_connection,
|
||||
struct aws_http2_setting out_settings[AWS_HTTP2_SETTINGS_COUNT]);
|
||||
|
||||
/**
|
||||
* Get the settings received from remote peer, which we are using to restricts the message to send.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param out_settings fixed size array of aws_http2_setting gets set to the remote settings
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http2_connection_get_remote_settings(
|
||||
const struct aws_http_connection *http2_connection,
|
||||
struct aws_http2_setting out_settings[AWS_HTTP2_SETTINGS_COUNT]);
|
||||
|
||||
/**
|
||||
* Send a custom GOAWAY frame (HTTP/2 only).
|
||||
*
|
||||
* Note that the connection automatically attempts to send a GOAWAY during
|
||||
* shutdown (unless a GOAWAY with a valid Last-Stream-ID has already been sent).
|
||||
*
|
||||
* This call can be used to gracefully warn the peer of an impending shutdown
|
||||
* (http2_error=0, allow_more_streams=true), or to customize the final GOAWAY
|
||||
* frame that is sent by this connection.
|
||||
*
|
||||
* The other end may not receive the goaway, if the connection already closed.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param http2_error The HTTP/2 error code (RFC-7540 section 7) to send.
|
||||
* `enum aws_http2_error_code` lists official codes.
|
||||
* @param allow_more_streams If true, new peer-initiated streams will continue
|
||||
* to be acknowledged and the GOAWAY's Last-Stream-ID will be set to a max value.
|
||||
* If false, new peer-initiated streams will be ignored and the GOAWAY's
|
||||
* Last-Stream-ID will be set to the latest acknowledged stream.
|
||||
* @param optional_debug_data Optional debug data to send. Size must not exceed 16KB.
|
||||
*/
|
||||
|
||||
AWS_HTTP_API
|
||||
void aws_http2_connection_send_goaway(
|
||||
struct aws_http_connection *http2_connection,
|
||||
uint32_t http2_error,
|
||||
bool allow_more_streams,
|
||||
const struct aws_byte_cursor *optional_debug_data);
|
||||
|
||||
/**
|
||||
* Get data about the latest GOAWAY frame sent to peer (HTTP/2 only).
|
||||
* If no GOAWAY has been sent, AWS_ERROR_HTTP_DATA_NOT_AVAILABLE will be raised.
|
||||
* Note that GOAWAY frames are typically sent automatically by the connection
|
||||
* during shutdown.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param out_http2_error Gets set to HTTP/2 error code sent in most recent GOAWAY.
|
||||
* @param out_last_stream_id Gets set to Last-Stream-ID sent in most recent GOAWAY.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http2_connection_get_sent_goaway(
|
||||
struct aws_http_connection *http2_connection,
|
||||
uint32_t *out_http2_error,
|
||||
uint32_t *out_last_stream_id);
|
||||
|
||||
/**
|
||||
* Get data about the latest GOAWAY frame received from peer (HTTP/2 only).
|
||||
* If no GOAWAY has been received, or the GOAWAY payload is still in transmitting,
|
||||
* AWS_ERROR_HTTP_DATA_NOT_AVAILABLE will be raised.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param out_http2_error Gets set to HTTP/2 error code received in most recent GOAWAY.
|
||||
* @param out_last_stream_id Gets set to Last-Stream-ID received in most recent GOAWAY.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http2_connection_get_received_goaway(
|
||||
struct aws_http_connection *http2_connection,
|
||||
uint32_t *out_http2_error,
|
||||
uint32_t *out_last_stream_id);
|
||||
|
||||
/**
|
||||
* Increment the connection's flow-control window to keep data flowing (HTTP/2 only).
|
||||
*
|
||||
* If the connection was created with `conn_manual_window_management` set true,
|
||||
* the flow-control window of the connection will shrink as body data is received for all the streams created on it.
|
||||
* (headers, padding, and other metadata do not affect the window).
|
||||
* The initial connection flow-control window is 65,535.
|
||||
* Once the connection's flow-control window reaches to 0, all the streams on the connection stop receiving any further
|
||||
* data.
|
||||
*
|
||||
* If `conn_manual_window_management` is false, this call will have no effect.
|
||||
* The connection maintains its flow-control windows such that
|
||||
* no back-pressure is applied and data arrives as fast as possible.
|
||||
*
|
||||
* If you are not connected, this call will have no effect.
|
||||
*
|
||||
* Crashes when the connection is not http2 connection.
|
||||
* The limit of the Maximum Size is 2**31 - 1. If the increment size cause the connection flow window exceeds the
|
||||
* Maximum size, this call will result in the connection lost.
|
||||
*
|
||||
* @param http2_connection HTTP/2 connection.
|
||||
* @param increment_size The size to increment for the connection's flow control window
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http2_connection_update_window(struct aws_http_connection *http2_connection, uint32_t increment_size);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_CONNECTION_H */
|
||||
@@ -0,0 +1,226 @@
|
||||
#ifndef AWS_HTTP_CONNECTION_MANAGER_H
|
||||
#define AWS_HTTP_CONNECTION_MANAGER_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
#include <aws/common/byte_buf.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_client_bootstrap;
|
||||
struct aws_http_connection;
|
||||
struct aws_http_connection_manager;
|
||||
struct aws_socket_options;
|
||||
struct aws_tls_connection_options;
|
||||
struct proxy_env_var_settings;
|
||||
struct aws_http2_setting;
|
||||
|
||||
typedef void(aws_http_connection_manager_on_connection_setup_fn)(
|
||||
struct aws_http_connection *connection,
|
||||
int error_code,
|
||||
void *user_data);
|
||||
|
||||
typedef void(aws_http_connection_manager_shutdown_complete_fn)(void *user_data);
|
||||
|
||||
/**
|
||||
* Metrics for logging and debugging purpose.
|
||||
*/
|
||||
struct aws_http_manager_metrics {
|
||||
/**
|
||||
* The number of additional concurrent requests that can be supported by the HTTP manager without needing to
|
||||
* establish additional connections to the target server.
|
||||
*
|
||||
* For connection manager, it equals to connections that's idle.
|
||||
* For stream manager, it equals to the number of streams that are possible to be made without creating new
|
||||
* connection, although the implementation can create new connection without fully filling it.
|
||||
*/
|
||||
size_t available_concurrency;
|
||||
/* The number of requests that are awaiting concurrency to be made available from the HTTP manager. */
|
||||
size_t pending_concurrency_acquires;
|
||||
/* The number of connections (http/1.1) or streams (for h2 via. stream manager) currently vended to user. */
|
||||
size_t leased_concurrency;
|
||||
};
|
||||
|
||||
/*
|
||||
* Connection manager configuration struct.
|
||||
*
|
||||
* Contains all of the configuration needed to create an http connection as well as
|
||||
* the maximum number of connections to ever have in existence.
|
||||
*/
|
||||
struct aws_http_connection_manager_options {
|
||||
/*
|
||||
* http connection configuration, check `struct aws_http_client_connection_options` for details of each config
|
||||
*/
|
||||
struct aws_client_bootstrap *bootstrap;
|
||||
size_t initial_window_size;
|
||||
const struct aws_socket_options *socket_options;
|
||||
|
||||
/**
|
||||
* Options to create secure (HTTPS) connections.
|
||||
* For secure connections, set "h2" in the ALPN string for HTTP/2, otherwise HTTP/1.1 is used.
|
||||
*
|
||||
* Leave NULL to create cleartext (HTTP) connections.
|
||||
* For cleartext connections, use `http2_prior_knowledge` (RFC-7540 3.4)
|
||||
* to control whether that are treated as HTTP/1.1 or HTTP/2.
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_connection_options;
|
||||
|
||||
/**
|
||||
* Specify whether you have prior knowledge that cleartext (HTTP) connections are HTTP/2 (RFC-7540 3.4).
|
||||
* If false, then cleartext connections are treated as HTTP/1.1.
|
||||
* It is illegal to set this true when secure connections are being used.
|
||||
* Note that upgrading from HTTP/1.1 to HTTP/2 is not supported (RFC-7540 3.2).
|
||||
*/
|
||||
bool http2_prior_knowledge;
|
||||
|
||||
const struct aws_http_connection_monitoring_options *monitoring_options;
|
||||
struct aws_byte_cursor host;
|
||||
uint32_t port;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* HTTP/2 specific configuration. Check `struct aws_http2_connection_options` for details of each config
|
||||
*/
|
||||
const struct aws_http2_setting *initial_settings_array;
|
||||
size_t num_initial_settings;
|
||||
size_t max_closed_streams;
|
||||
bool http2_conn_manual_window_management;
|
||||
|
||||
/* Proxy configuration for http connection */
|
||||
const struct aws_http_proxy_options *proxy_options;
|
||||
|
||||
/*
|
||||
* Optional.
|
||||
* Configuration for using proxy from environment variable.
|
||||
* Only works when proxy_options is not set.
|
||||
*/
|
||||
const struct proxy_env_var_settings *proxy_ev_settings;
|
||||
|
||||
/*
|
||||
* Maximum number of connections this manager is allowed to contain
|
||||
*/
|
||||
size_t max_connections;
|
||||
|
||||
/*
|
||||
* Callback and associated user data to invoke when the connection manager has
|
||||
* completely shutdown and has finished deleting itself.
|
||||
* Technically optional, but correctness may be impossible without it.
|
||||
*/
|
||||
void *shutdown_complete_user_data;
|
||||
aws_http_connection_manager_shutdown_complete_fn *shutdown_complete_callback;
|
||||
|
||||
/**
|
||||
* If set to true, the read back pressure mechanism will be enabled.
|
||||
*/
|
||||
bool enable_read_back_pressure;
|
||||
|
||||
/**
|
||||
* If set to a non-zero value, then connections that stay in the pool longer than the specified
|
||||
* timeout will be closed automatically.
|
||||
*/
|
||||
uint64_t max_connection_idle_in_milliseconds;
|
||||
|
||||
/**
|
||||
* If set to a non-zero value, aws_http_connection_manager_acquire_connection() calls
|
||||
* will give up after waiting this long for a connection from the pool,
|
||||
* failing with error AWS_ERROR_HTTP_CONNECTION_MANAGER_ACQUISITION_TIMEOUT.
|
||||
*/
|
||||
uint64_t connection_acquisition_timeout_ms;
|
||||
|
||||
/*
|
||||
* If set to a non-zero value, aws_http_connection_manager_acquire_connection() calls will fail with
|
||||
* AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED if the number of pending acquisitions
|
||||
* reaches `max_pending_connection_acquisitions` after the connection pool has reached its capacity (i.e., all
|
||||
* `num_connections` have been vended).
|
||||
*/
|
||||
uint64_t max_pending_connection_acquisitions;
|
||||
|
||||
/**
|
||||
* THIS IS AN EXPERIMENTAL AND UNSTABLE API
|
||||
* (Optional)
|
||||
* An array of network interface names. The manager will distribute the
|
||||
* connections across network interface names provided in this array. If any interface name is invalid, goes down,
|
||||
* or has any issues like network access, you will see connection failures. If
|
||||
* `socket_options.network_interface_name` is also set, an `AWS_ERROR_INVALID_ARGUMENT` error will be raised.
|
||||
*
|
||||
* This option is only supported on Linux, MacOS, and platforms that have either SO_BINDTODEVICE or IP_BOUND_IF. It
|
||||
* is not supported on Windows. `AWS_ERROR_PLATFORM_NOT_SUPPORTED` will be raised on unsupported platforms.
|
||||
*/
|
||||
const struct aws_byte_cursor *network_interface_names_array;
|
||||
size_t num_network_interface_names;
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/*
|
||||
* Connection managers are ref counted. Adds one external ref to the manager.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_manager_acquire(struct aws_http_connection_manager *manager);
|
||||
|
||||
/*
|
||||
* Connection managers are ref counted. Removes one external ref from the manager.
|
||||
*
|
||||
* When the ref count goes to zero, the connection manager begins its shut down
|
||||
* process. All pending connection acquisitions are failed (with callbacks
|
||||
* invoked) and any (erroneous) subsequent attempts to acquire a connection
|
||||
* fail immediately. The connection manager destroys itself once all pending
|
||||
* asynchronous activities have resolved.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_manager_release(struct aws_http_connection_manager *manager);
|
||||
|
||||
/*
|
||||
* Creates a new connection manager with the supplied configuration options.
|
||||
*
|
||||
* The returned connection manager begins with a ref count of 1.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_connection_manager *aws_http_connection_manager_new(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_connection_manager_options *options);
|
||||
|
||||
/*
|
||||
* Requests a connection from the manager. The requester is notified of
|
||||
* an acquired connection (or failure to acquire) via the supplied callback.
|
||||
*
|
||||
* For HTTP/2 connections, the callback will not fire until the server's settings have been received.
|
||||
*
|
||||
* Once a connection has been successfully acquired from the manager it
|
||||
* must be released back (via aws_http_connection_manager_release_connection)
|
||||
* at some point. Failure to do so will cause a resource leak.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_manager_acquire_connection(
|
||||
struct aws_http_connection_manager *manager,
|
||||
aws_http_connection_manager_on_connection_setup_fn *callback,
|
||||
void *user_data);
|
||||
|
||||
/*
|
||||
* Returns a connection back to the manager. All acquired connections must
|
||||
* eventually be released back to the manager in order to avoid a resource leak.
|
||||
*
|
||||
* Note: it can lead to another acquired callback to be invoked within the thread.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_connection_manager_release_connection(
|
||||
struct aws_http_connection_manager *manager,
|
||||
struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Fetch the current manager metrics from connection manager.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_connection_manager_fetch_metrics(
|
||||
const struct aws_http_connection_manager *manager,
|
||||
struct aws_http_manager_metrics *out_metrics);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_CONNECTION_MANAGER_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef AWS_HTTP_EXPORTS_H
|
||||
#define AWS_HTTP_EXPORTS_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#if defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32)
|
||||
# ifdef AWS_HTTP_USE_IMPORT_EXPORT
|
||||
# ifdef AWS_HTTP_EXPORTS
|
||||
# define AWS_HTTP_API __declspec(dllexport)
|
||||
# else
|
||||
# define AWS_HTTP_API __declspec(dllimport)
|
||||
# endif /* AWS_HTTP_EXPORTS */
|
||||
# else
|
||||
# define AWS_HTTP_API
|
||||
# endif /* USE_IMPORT_EXPORT */
|
||||
|
||||
#else
|
||||
# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_HTTP_USE_IMPORT_EXPORT) && defined(AWS_HTTP_EXPORTS)
|
||||
# define AWS_HTTP_API __attribute__((visibility("default")))
|
||||
# else
|
||||
# define AWS_HTTP_API
|
||||
# endif /* __GNUC__ >= 4 || defined(__clang__) */
|
||||
|
||||
#endif /* defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32) */
|
||||
|
||||
#endif /* AWS_HTTP_EXPORTS_H */
|
||||
164
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/http.h
Normal file
164
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/http.h
Normal file
@@ -0,0 +1,164 @@
|
||||
#ifndef AWS_HTTP_H
|
||||
#define AWS_HTTP_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/common/logging.h>
|
||||
#include <aws/http/exports.h>
|
||||
#include <aws/io/io.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
#define AWS_C_HTTP_PACKAGE_ID 2
|
||||
|
||||
enum aws_http_errors {
|
||||
AWS_ERROR_HTTP_UNKNOWN = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_HTTP_PACKAGE_ID),
|
||||
AWS_ERROR_HTTP_HEADER_NOT_FOUND,
|
||||
AWS_ERROR_HTTP_INVALID_HEADER_FIELD,
|
||||
AWS_ERROR_HTTP_INVALID_HEADER_NAME,
|
||||
AWS_ERROR_HTTP_INVALID_HEADER_VALUE,
|
||||
AWS_ERROR_HTTP_INVALID_METHOD,
|
||||
AWS_ERROR_HTTP_INVALID_PATH,
|
||||
AWS_ERROR_HTTP_INVALID_STATUS_CODE,
|
||||
AWS_ERROR_HTTP_MISSING_BODY_STREAM,
|
||||
AWS_ERROR_HTTP_INVALID_BODY_STREAM,
|
||||
AWS_ERROR_HTTP_CONNECTION_CLOSED,
|
||||
AWS_ERROR_HTTP_SWITCHED_PROTOCOLS,
|
||||
AWS_ERROR_HTTP_UNSUPPORTED_PROTOCOL,
|
||||
AWS_ERROR_HTTP_REACTION_REQUIRED,
|
||||
AWS_ERROR_HTTP_DATA_NOT_AVAILABLE,
|
||||
AWS_ERROR_HTTP_OUTGOING_STREAM_LENGTH_INCORRECT,
|
||||
AWS_ERROR_HTTP_CALLBACK_FAILURE,
|
||||
AWS_ERROR_HTTP_WEBSOCKET_UPGRADE_FAILURE,
|
||||
AWS_ERROR_HTTP_WEBSOCKET_CLOSE_FRAME_SENT,
|
||||
AWS_ERROR_HTTP_WEBSOCKET_IS_MIDCHANNEL_HANDLER,
|
||||
AWS_ERROR_HTTP_CONNECTION_MANAGER_INVALID_STATE_FOR_ACQUIRE,
|
||||
AWS_ERROR_HTTP_CONNECTION_MANAGER_VENDED_CONNECTION_UNDERFLOW,
|
||||
AWS_ERROR_HTTP_SERVER_CLOSED,
|
||||
AWS_ERROR_HTTP_PROXY_CONNECT_FAILED,
|
||||
AWS_ERROR_HTTP_CONNECTION_MANAGER_SHUTTING_DOWN,
|
||||
AWS_ERROR_HTTP_CHANNEL_THROUGHPUT_FAILURE,
|
||||
AWS_ERROR_HTTP_PROTOCOL_ERROR,
|
||||
AWS_ERROR_HTTP_STREAM_IDS_EXHAUSTED,
|
||||
AWS_ERROR_HTTP_GOAWAY_RECEIVED,
|
||||
AWS_ERROR_HTTP_RST_STREAM_RECEIVED,
|
||||
AWS_ERROR_HTTP_RST_STREAM_SENT,
|
||||
AWS_ERROR_HTTP_STREAM_NOT_ACTIVATED,
|
||||
AWS_ERROR_HTTP_STREAM_HAS_COMPLETED,
|
||||
AWS_ERROR_HTTP_PROXY_STRATEGY_NTLM_CHALLENGE_TOKEN_MISSING,
|
||||
AWS_ERROR_HTTP_PROXY_STRATEGY_TOKEN_RETRIEVAL_FAILURE,
|
||||
AWS_ERROR_HTTP_PROXY_CONNECT_FAILED_RETRYABLE,
|
||||
AWS_ERROR_HTTP_PROTOCOL_SWITCH_FAILURE,
|
||||
AWS_ERROR_HTTP_MAX_CONCURRENT_STREAMS_EXCEEDED,
|
||||
AWS_ERROR_HTTP_STREAM_MANAGER_SHUTTING_DOWN,
|
||||
AWS_ERROR_HTTP_STREAM_MANAGER_CONNECTION_ACQUIRE_FAILURE,
|
||||
AWS_ERROR_HTTP_STREAM_MANAGER_UNEXPECTED_HTTP_VERSION,
|
||||
AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR,
|
||||
AWS_ERROR_HTTP_MANUAL_WRITE_NOT_ENABLED,
|
||||
AWS_ERROR_HTTP_MANUAL_WRITE_HAS_COMPLETED,
|
||||
AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT,
|
||||
AWS_ERROR_HTTP_CONNECTION_MANAGER_ACQUISITION_TIMEOUT,
|
||||
AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED,
|
||||
|
||||
AWS_ERROR_HTTP_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_HTTP_PACKAGE_ID)
|
||||
};
|
||||
|
||||
/* Error codes that may be present in HTTP/2 RST_STREAM and GOAWAY frames (RFC-7540 7). */
|
||||
enum aws_http2_error_code {
|
||||
AWS_HTTP2_ERR_NO_ERROR = 0x00,
|
||||
AWS_HTTP2_ERR_PROTOCOL_ERROR = 0x01,
|
||||
AWS_HTTP2_ERR_INTERNAL_ERROR = 0x02,
|
||||
AWS_HTTP2_ERR_FLOW_CONTROL_ERROR = 0x03,
|
||||
AWS_HTTP2_ERR_SETTINGS_TIMEOUT = 0x04,
|
||||
AWS_HTTP2_ERR_STREAM_CLOSED = 0x05,
|
||||
AWS_HTTP2_ERR_FRAME_SIZE_ERROR = 0x06,
|
||||
AWS_HTTP2_ERR_REFUSED_STREAM = 0x07,
|
||||
AWS_HTTP2_ERR_CANCEL = 0x08,
|
||||
AWS_HTTP2_ERR_COMPRESSION_ERROR = 0x09,
|
||||
AWS_HTTP2_ERR_CONNECT_ERROR = 0x0A,
|
||||
AWS_HTTP2_ERR_ENHANCE_YOUR_CALM = 0x0B,
|
||||
AWS_HTTP2_ERR_INADEQUATE_SECURITY = 0x0C,
|
||||
AWS_HTTP2_ERR_HTTP_1_1_REQUIRED = 0x0D,
|
||||
AWS_HTTP2_ERR_COUNT,
|
||||
};
|
||||
|
||||
enum aws_http_log_subject {
|
||||
AWS_LS_HTTP_GENERAL = AWS_LOG_SUBJECT_BEGIN_RANGE(AWS_C_HTTP_PACKAGE_ID),
|
||||
AWS_LS_HTTP_CONNECTION,
|
||||
AWS_LS_HTTP_ENCODER,
|
||||
AWS_LS_HTTP_DECODER,
|
||||
AWS_LS_HTTP_SERVER,
|
||||
AWS_LS_HTTP_STREAM,
|
||||
AWS_LS_HTTP_CONNECTION_MANAGER,
|
||||
AWS_LS_HTTP_STREAM_MANAGER,
|
||||
AWS_LS_HTTP_WEBSOCKET,
|
||||
AWS_LS_HTTP_WEBSOCKET_SETUP,
|
||||
AWS_LS_HTTP_PROXY_NEGOTIATION,
|
||||
};
|
||||
|
||||
enum aws_http_version {
|
||||
AWS_HTTP_VERSION_UNKNOWN, /* Invalid version. */
|
||||
AWS_HTTP_VERSION_1_0,
|
||||
AWS_HTTP_VERSION_1_1,
|
||||
AWS_HTTP_VERSION_2,
|
||||
AWS_HTTP_VERSION_COUNT,
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Initializes internal datastructures used by aws-c-http.
|
||||
* Must be called before using any functionality in aws-c-http.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_library_init(struct aws_allocator *alloc);
|
||||
|
||||
/**
|
||||
* Clean up internal datastructures used by aws-c-http.
|
||||
* Must not be called until application is done using functionality in aws-c-http.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_library_clean_up(void);
|
||||
|
||||
/**
|
||||
* Returns the description of common status codes.
|
||||
* Ex: 404 -> "Not Found"
|
||||
* An empty string is returned if the status code is not recognized.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
const char *aws_http_status_text(int status_code);
|
||||
|
||||
/**
|
||||
* Shortcuts for common HTTP request methods
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_get;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_head;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_post;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_put;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_delete;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_connect;
|
||||
AWS_HTTP_API
|
||||
extern const struct aws_byte_cursor aws_http_method_options;
|
||||
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_header_method;
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_header_scheme;
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_header_authority;
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_header_path;
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_header_status;
|
||||
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_scheme_http;
|
||||
AWS_HTTP_API extern const struct aws_byte_cursor aws_http_scheme_https;
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_H */
|
||||
@@ -0,0 +1,219 @@
|
||||
#ifndef AWS_HTTP2_STREAM_MANAGER_H
|
||||
#define AWS_HTTP2_STREAM_MANAGER_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_http2_stream_manager;
|
||||
struct aws_client_bootstrap;
|
||||
struct aws_http_connection;
|
||||
struct aws_http_connection_manager;
|
||||
struct aws_socket_options;
|
||||
struct aws_tls_connection_options;
|
||||
struct proxy_env_var_settings;
|
||||
struct aws_http2_setting;
|
||||
struct aws_http_make_request_options;
|
||||
struct aws_http_stream;
|
||||
struct aws_http_manager_metrics;
|
||||
|
||||
/**
|
||||
* Always invoked asynchronously when the stream was created, successfully or not.
|
||||
* When stream is NULL, error code will be set to indicate what happened.
|
||||
* If there is a stream returned, you own the stream completely.
|
||||
* Invoked on the same thread as other callback of the stream, which will be the thread of the connection, ideally.
|
||||
* If there is no connection made, the callback will be invoked from a sperate thread.
|
||||
*/
|
||||
typedef void(
|
||||
aws_http2_stream_manager_on_stream_acquired_fn)(struct aws_http_stream *stream, int error_code, void *user_data);
|
||||
|
||||
/**
|
||||
* Invoked asynchronously when the stream manager has been shutdown completely.
|
||||
* Never invoked when `aws_http2_stream_manager_new` failed.
|
||||
*/
|
||||
typedef void(aws_http2_stream_manager_shutdown_complete_fn)(void *user_data);
|
||||
|
||||
/**
|
||||
* HTTP/2 stream manager configuration struct.
|
||||
*
|
||||
* Contains all of the configuration needed to create an http2 connection as well as
|
||||
* connection manager under the hood.
|
||||
*/
|
||||
struct aws_http2_stream_manager_options {
|
||||
/**
|
||||
* basic http connection configuration
|
||||
*/
|
||||
struct aws_client_bootstrap *bootstrap;
|
||||
const struct aws_socket_options *socket_options;
|
||||
|
||||
/**
|
||||
* Options to create secure (HTTPS) connections.
|
||||
* For secure connections, the ALPN string must be "h2".
|
||||
*
|
||||
* To create cleartext (HTTP) connections, leave this NULL
|
||||
* and set `http2_prior_knowledge` (RFC-7540 3.4).
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_connection_options;
|
||||
|
||||
/**
|
||||
* Specify whether you have prior knowledge that cleartext (HTTP) connections are HTTP/2 (RFC-7540 3.4).
|
||||
* It is illegal to set this true when secure connections are being used.
|
||||
* Note that upgrading from HTTP/1.1 to HTTP/2 is not supported (RFC-7540 3.2).
|
||||
*/
|
||||
bool http2_prior_knowledge;
|
||||
|
||||
struct aws_byte_cursor host;
|
||||
uint32_t port;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* HTTP/2 connection configuration. Check `struct aws_http2_connection_options` for details of each config.
|
||||
* Notes for window control:
|
||||
* - By default, client will will maintain its flow-control windows such that no back-pressure is applied and data
|
||||
* arrives as fast as possible.
|
||||
* - For connection level window control, `conn_manual_window_management` will enable manual control. The
|
||||
* inital window size is not controllable.
|
||||
* - For stream level window control, `enable_read_back_pressure` will enable manual control. The initial window
|
||||
* size needs to be set through `initial_settings_array`.
|
||||
*/
|
||||
const struct aws_http2_setting *initial_settings_array;
|
||||
size_t num_initial_settings;
|
||||
size_t max_closed_streams;
|
||||
bool conn_manual_window_management;
|
||||
|
||||
/**
|
||||
* HTTP/2 Stream window control.
|
||||
* If set to true, the read back pressure mechanism will be enabled for streams created.
|
||||
* The initial window size can be set by `AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE` via `initial_settings_array`
|
||||
*/
|
||||
bool enable_read_back_pressure;
|
||||
|
||||
/* Connection monitor for the underlying connections made */
|
||||
const struct aws_http_connection_monitoring_options *monitoring_options;
|
||||
|
||||
/* Optional. Proxy configuration for underlying http connection */
|
||||
const struct aws_http_proxy_options *proxy_options;
|
||||
const struct proxy_env_var_settings *proxy_ev_settings;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* When the stream manager finishes deleting all the resources, the callback will be invoked.
|
||||
*/
|
||||
void *shutdown_complete_user_data;
|
||||
aws_http2_stream_manager_shutdown_complete_fn *shutdown_complete_callback;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* When set, connection will be closed if 5xx response received from server.
|
||||
*/
|
||||
bool close_connection_on_server_error;
|
||||
/**
|
||||
* Optional.
|
||||
* The period for all the connections held by stream manager to send a PING in milliseconds.
|
||||
* If you specify 0, manager will NOT send any PING.
|
||||
* Note: if set, it must be large than the time of ping timeout setting.
|
||||
*/
|
||||
size_t connection_ping_period_ms;
|
||||
/**
|
||||
* Optional.
|
||||
* Network connection will be closed if a ping response is not received
|
||||
* within this amount of time (milliseconds).
|
||||
* If you specify 0, a default value will be used.
|
||||
*/
|
||||
size_t connection_ping_timeout_ms;
|
||||
|
||||
/* TODO: More flexible policy about the connections, but will always has these three values below. */
|
||||
/**
|
||||
* Optional.
|
||||
* 0 will be considered as using a default value.
|
||||
* The ideal number of concurrent streams for a connection. Stream manager will try to create a new connection if
|
||||
* one connection reaches this number. But, if the max connections reaches, manager will reuse connections to create
|
||||
* the acquired steams as much as possible. */
|
||||
size_t ideal_concurrent_streams_per_connection;
|
||||
/**
|
||||
* Optional.
|
||||
* Default is no limit, which will use the limit from the server. 0 will be considered as using the default value.
|
||||
* The real number of concurrent streams per connection will be controlled by the minmal value of the setting from
|
||||
* other end and the value here.
|
||||
*/
|
||||
size_t max_concurrent_streams_per_connection;
|
||||
/**
|
||||
* Required.
|
||||
* The max number of connections will be open at same time. If all the connections are full, manager will wait until
|
||||
* available to vender more streams */
|
||||
size_t max_connections;
|
||||
};
|
||||
|
||||
struct aws_http2_stream_manager_acquire_stream_options {
|
||||
/**
|
||||
* Required.
|
||||
* Invoked when the stream finishes acquiring by stream manager.
|
||||
*/
|
||||
aws_http2_stream_manager_on_stream_acquired_fn *callback;
|
||||
/**
|
||||
* Optional.
|
||||
* User data for the callback.
|
||||
*/
|
||||
void *user_data;
|
||||
/* Required. see `aws_http_make_request_options` */
|
||||
const struct aws_http_make_request_options *options;
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Acquire a refcount from the stream manager, stream manager will start to destroy after the refcount drops to zero.
|
||||
* NULL is acceptable. Initial refcount after new is 1.
|
||||
*
|
||||
* @param manager
|
||||
* @return The same pointer acquiring.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http2_stream_manager *aws_http2_stream_manager_acquire(struct aws_http2_stream_manager *manager);
|
||||
|
||||
/**
|
||||
* Release a refcount from the stream manager, stream manager will start to destroy after the refcount drops to zero.
|
||||
* NULL is acceptable. Initial refcount after new is 1.
|
||||
*
|
||||
* @param manager
|
||||
* @return NULL
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http2_stream_manager *aws_http2_stream_manager_release(struct aws_http2_stream_manager *manager);
|
||||
|
||||
AWS_HTTP_API
|
||||
struct aws_http2_stream_manager *aws_http2_stream_manager_new(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http2_stream_manager_options *options);
|
||||
|
||||
/**
|
||||
* Acquire a stream from stream manager asynchronously.
|
||||
*
|
||||
* @param http2_stream_manager
|
||||
* @param acquire_stream_option see `aws_http2_stream_manager_acquire_stream_options`
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http2_stream_manager_acquire_stream(
|
||||
struct aws_http2_stream_manager *http2_stream_manager,
|
||||
const struct aws_http2_stream_manager_acquire_stream_options *acquire_stream_option);
|
||||
|
||||
/**
|
||||
* Fetch the current metrics from stream manager.
|
||||
*
|
||||
* @param http2_stream_manager
|
||||
* @param out_metrics The metrics to be fetched
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http2_stream_manager_fetch_metrics(
|
||||
const struct aws_http2_stream_manager *http2_stream_manager,
|
||||
struct aws_http_manager_metrics *out_metrics);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP2_STREAM_MANAGER_H */
|
||||
573
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/proxy.h
Normal file
573
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/proxy.h
Normal file
@@ -0,0 +1,573 @@
|
||||
#ifndef AWS_PROXY_H
|
||||
#define AWS_PROXY_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/common/ref_count.h>
|
||||
#include <aws/http/http.h>
|
||||
#include <aws/http/request_response.h>
|
||||
#include <aws/http/status_code.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_http_client_connection_options;
|
||||
struct aws_http_connection_manager_options;
|
||||
|
||||
struct aws_http_message;
|
||||
struct aws_http_header;
|
||||
|
||||
struct aws_http_proxy_config;
|
||||
struct aws_http_proxy_negotiator;
|
||||
struct aws_http_proxy_strategy;
|
||||
|
||||
struct aws_socket_channel_bootstrap_options;
|
||||
|
||||
/**
|
||||
* @Deprecated - Supported proxy authentication modes. Superceded by proxy strategy.
|
||||
*/
|
||||
enum aws_http_proxy_authentication_type {
|
||||
AWS_HPAT_NONE = 0,
|
||||
AWS_HPAT_BASIC,
|
||||
};
|
||||
|
||||
enum aws_http_proxy_env_var_type {
|
||||
/**
|
||||
* Default.
|
||||
* Disable reading from environment variable for proxy.
|
||||
*/
|
||||
AWS_HPEV_DISABLE = 0,
|
||||
/**
|
||||
* Enable get proxy URL from environment variable, when the manual proxy options of connection manager is not set.
|
||||
* env HTTPS_PROXY/https_proxy will be checked when the main connection use tls.
|
||||
* env HTTP_PROXY/http_proxy will be checked when the main connection NOT use tls.
|
||||
* The lower case version has precedence.
|
||||
*/
|
||||
AWS_HPEV_ENABLE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Supported proxy connection types
|
||||
*/
|
||||
enum aws_http_proxy_connection_type {
|
||||
/**
|
||||
* Deprecated, but 0-valued for backwards compatibility
|
||||
*
|
||||
* If tls options are provided (for the main connection) then treat the proxy as a tunneling proxy
|
||||
* If tls options are not provided (for the main connection), then treat the proxy as a forwarding proxy
|
||||
*/
|
||||
AWS_HPCT_HTTP_LEGACY = 0,
|
||||
|
||||
/**
|
||||
* Use the proxy to forward http requests. Attempting to use both this mode and TLS on the tunnel destination
|
||||
* is a configuration error.
|
||||
*/
|
||||
AWS_HPCT_HTTP_FORWARD,
|
||||
|
||||
/**
|
||||
* Use the proxy to establish a connection to a remote endpoint via a CONNECT request through the proxy.
|
||||
* Works for both plaintext and tls connections.
|
||||
*/
|
||||
AWS_HPCT_HTTP_TUNNEL,
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration for using proxy from environment variable.
|
||||
* Zero out as default settings.
|
||||
*/
|
||||
struct proxy_env_var_settings {
|
||||
enum aws_http_proxy_env_var_type env_var_type;
|
||||
/*
|
||||
* Optional.
|
||||
* If not set:
|
||||
* If tls options are provided (for the main connection) use tunnel proxy type
|
||||
* If tls options are not provided (for the main connection) use forward proxy type
|
||||
*/
|
||||
enum aws_http_proxy_connection_type connection_type;
|
||||
/*
|
||||
* Optional.
|
||||
* If not set, a default tls option will be created. when https used for Local to proxy connection.
|
||||
* Must be distinct from the the tls_connection_options from aws_http_connection_manager_options
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_options;
|
||||
};
|
||||
|
||||
struct aws_http_proxy_strategy;
|
||||
|
||||
/**
|
||||
* Options for http proxy server usage
|
||||
*/
|
||||
struct aws_http_proxy_options {
|
||||
|
||||
/**
|
||||
* Type of proxy connection to make
|
||||
*/
|
||||
enum aws_http_proxy_connection_type connection_type;
|
||||
|
||||
/**
|
||||
* Proxy host to connect to
|
||||
*/
|
||||
struct aws_byte_cursor host;
|
||||
|
||||
/**
|
||||
* Port to make the proxy connection to
|
||||
*/
|
||||
uint32_t port;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* TLS configuration for the Local <-> Proxy connection
|
||||
* Must be distinct from the the TLS options in the parent aws_http_connection_options struct
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_options;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Advanced option that allows the user to create a custom strategy that gives low-level control of
|
||||
* certain logical flows within the proxy logic.
|
||||
*
|
||||
* For tunneling proxies it allows custom retry and adaptive negotiation of CONNECT requests.
|
||||
* For forwarding proxies it allows custom request transformations.
|
||||
*/
|
||||
struct aws_http_proxy_strategy *proxy_strategy;
|
||||
|
||||
/**
|
||||
* @Deprecated - What type of proxy authentication to use, if any.
|
||||
* Replaced by instantiating a proxy_strategy
|
||||
*/
|
||||
enum aws_http_proxy_authentication_type auth_type;
|
||||
|
||||
/**
|
||||
* @Deprecated - Optional user name to use for basic authentication
|
||||
* Replaced by instantiating a proxy_strategy via aws_http_proxy_strategy_new_basic_auth()
|
||||
*/
|
||||
struct aws_byte_cursor auth_username;
|
||||
|
||||
/**
|
||||
* @Deprecated - Optional password to use for basic authentication
|
||||
* Replaced by instantiating a proxy_strategy via aws_http_proxy_strategy_new_basic_auth()
|
||||
*/
|
||||
struct aws_byte_cursor auth_password;
|
||||
};
|
||||
|
||||
/**
|
||||
* Synchronous (for now) callback function to fetch a token used in modifying CONNECT requests
|
||||
*/
|
||||
typedef struct aws_string *(aws_http_proxy_negotiation_get_token_sync_fn)(void *user_data, int *out_error_code);
|
||||
|
||||
/**
|
||||
* Synchronous (for now) callback function to fetch a token used in modifying CONNECT request. Includes a (byte string)
|
||||
* context intended to be used as part of a challenge-response flow.
|
||||
*/
|
||||
typedef struct aws_string *(
|
||||
aws_http_proxy_negotiation_get_challenge_token_sync_fn)(void *user_data,
|
||||
const struct aws_byte_cursor *challenge_context,
|
||||
int *out_error_code);
|
||||
|
||||
/**
|
||||
* Proxy negotiation logic must call this function to indicate an unsuccessful outcome
|
||||
*/
|
||||
typedef void(aws_http_proxy_negotiation_terminate_fn)(
|
||||
struct aws_http_message *message,
|
||||
int error_code,
|
||||
void *internal_proxy_user_data);
|
||||
|
||||
/**
|
||||
* Proxy negotiation logic must call this function to forward the potentially-mutated request back to the proxy
|
||||
* connection logic.
|
||||
*/
|
||||
typedef void(aws_http_proxy_negotiation_http_request_forward_fn)(
|
||||
struct aws_http_message *message,
|
||||
void *internal_proxy_user_data);
|
||||
|
||||
/**
|
||||
* User-supplied transform callback which implements the proxy request flow and ultimately, across all execution
|
||||
* pathways, invokes either the terminate function or the forward function appropriately.
|
||||
*
|
||||
* For tunneling proxy connections, this request flow transform only applies to the CONNECT stage of proxy
|
||||
* connection establishment.
|
||||
*
|
||||
* For forwarding proxy connections, this request flow transform applies to every single http request that goes
|
||||
* out on the connection.
|
||||
*
|
||||
* Forwarding proxy connections cannot yet support a truly async request transform without major surgery on http
|
||||
* stream creation, so for now, we split into an async version (for tunneling proxies) and a separate
|
||||
* synchronous version for forwarding proxies. Also forwarding proxies are a kind of legacy dead-end in some
|
||||
* sense.
|
||||
*
|
||||
*/
|
||||
typedef void(aws_http_proxy_negotiation_http_request_transform_async_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator,
|
||||
struct aws_http_message *message,
|
||||
aws_http_proxy_negotiation_terminate_fn *negotiation_termination_callback,
|
||||
aws_http_proxy_negotiation_http_request_forward_fn *negotiation_http_request_forward_callback,
|
||||
void *internal_proxy_user_data);
|
||||
|
||||
typedef int(aws_http_proxy_negotiation_http_request_transform_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator,
|
||||
struct aws_http_message *message);
|
||||
|
||||
/**
|
||||
* Tunneling proxy connections only. A callback that lets the negotiator examine the headers in the
|
||||
* response to the most recent CONNECT request as they arrive.
|
||||
*/
|
||||
typedef int(aws_http_proxy_negotiation_connect_on_incoming_headers_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator,
|
||||
enum aws_http_header_block header_block,
|
||||
const struct aws_http_header *header_array,
|
||||
size_t num_headers);
|
||||
|
||||
/**
|
||||
* Tunneling proxy connections only. A callback that lets the negotiator examine the status code of the
|
||||
* response to the most recent CONNECT request.
|
||||
*/
|
||||
typedef int(aws_http_proxy_negotiator_connect_status_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator,
|
||||
enum aws_http_status_code status_code);
|
||||
|
||||
/**
|
||||
* Tunneling proxy connections only. A callback that lets the negotiator examine the body of the response
|
||||
* to the most recent CONNECT request.
|
||||
*/
|
||||
typedef int(aws_http_proxy_negotiator_connect_on_incoming_body_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator,
|
||||
const struct aws_byte_cursor *data);
|
||||
|
||||
/*
|
||||
* Control value that lets the http proxy implementation know if and how to retry a CONNECT request based on
|
||||
* the proxy negotiator's state.
|
||||
*/
|
||||
enum aws_http_proxy_negotiation_retry_directive {
|
||||
/*
|
||||
* Stop trying to connect through the proxy and give up.
|
||||
*/
|
||||
AWS_HPNRD_STOP,
|
||||
|
||||
/*
|
||||
* Establish a new connection to the proxy before making the next CONNECT request
|
||||
*/
|
||||
AWS_HPNRD_NEW_CONNECTION,
|
||||
|
||||
/*
|
||||
* Reuse the existing connection to make the next CONNECT request
|
||||
*/
|
||||
AWS_HPNRD_CURRENT_CONNECTION,
|
||||
};
|
||||
|
||||
typedef enum aws_http_proxy_negotiation_retry_directive(aws_http_proxy_negotiator_get_retry_directive_fn)(
|
||||
struct aws_http_proxy_negotiator *proxy_negotiator);
|
||||
|
||||
/**
|
||||
* Vtable for forwarding-based proxy negotiators
|
||||
*/
|
||||
struct aws_http_proxy_negotiator_forwarding_vtable {
|
||||
aws_http_proxy_negotiation_http_request_transform_fn *forward_request_transform;
|
||||
};
|
||||
|
||||
/**
|
||||
* Vtable for tunneling-based proxy negotiators
|
||||
*/
|
||||
struct aws_http_proxy_negotiator_tunnelling_vtable {
|
||||
aws_http_proxy_negotiation_http_request_transform_async_fn *connect_request_transform;
|
||||
|
||||
aws_http_proxy_negotiation_connect_on_incoming_headers_fn *on_incoming_headers_callback;
|
||||
aws_http_proxy_negotiator_connect_status_fn *on_status_callback;
|
||||
aws_http_proxy_negotiator_connect_on_incoming_body_fn *on_incoming_body_callback;
|
||||
|
||||
aws_http_proxy_negotiator_get_retry_directive_fn *get_retry_directive;
|
||||
};
|
||||
|
||||
/*
|
||||
* Base definition of a proxy negotiator.
|
||||
*
|
||||
* A negotiator works differently based on what kind of proxy connection is being asked for:
|
||||
*
|
||||
* (1) Tunneling - In a tunneling proxy connection, the connect_request_transform is invoked on every CONNECT request.
|
||||
* The connect_request_transform implementation *MUST*, in turn, eventually call one of the terminate or forward
|
||||
* functions it gets supplied with.
|
||||
*
|
||||
* Every CONNECT request, if a response is obtained, will properly invoke the response handling callbacks supplied
|
||||
* in the tunneling vtable.
|
||||
*
|
||||
* (2) Forwarding - In a forwarding proxy connection, the forward_request_transform is invoked on every request sent out
|
||||
* on the connection.
|
||||
*/
|
||||
struct aws_http_proxy_negotiator {
|
||||
struct aws_ref_count ref_count;
|
||||
|
||||
void *impl;
|
||||
|
||||
union {
|
||||
struct aws_http_proxy_negotiator_forwarding_vtable *forwarding_vtable;
|
||||
struct aws_http_proxy_negotiator_tunnelling_vtable *tunnelling_vtable;
|
||||
} strategy_vtable;
|
||||
};
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
typedef struct aws_http_proxy_negotiator *(
|
||||
aws_http_proxy_strategy_create_negotiator_fn)(struct aws_http_proxy_strategy *proxy_strategy,
|
||||
struct aws_allocator *allocator);
|
||||
|
||||
struct aws_http_proxy_strategy_vtable {
|
||||
aws_http_proxy_strategy_create_negotiator_fn *create_negotiator;
|
||||
};
|
||||
|
||||
struct aws_http_proxy_strategy {
|
||||
struct aws_ref_count ref_count;
|
||||
struct aws_http_proxy_strategy_vtable *vtable;
|
||||
void *impl;
|
||||
enum aws_http_proxy_connection_type proxy_connection_type;
|
||||
};
|
||||
|
||||
/*
|
||||
* Options necessary to create a basic authentication proxy strategy
|
||||
*/
|
||||
struct aws_http_proxy_strategy_basic_auth_options {
|
||||
|
||||
/* type of proxy connection being established, must be forwarding or tunnel */
|
||||
enum aws_http_proxy_connection_type proxy_connection_type;
|
||||
|
||||
/* user name to use in basic authentication */
|
||||
struct aws_byte_cursor user_name;
|
||||
|
||||
/* password to use in basic authentication */
|
||||
struct aws_byte_cursor password;
|
||||
};
|
||||
|
||||
/*
|
||||
* Options necessary to create a (synchronous) kerberos authentication proxy strategy
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_kerberos_options {
|
||||
|
||||
aws_http_proxy_negotiation_get_token_sync_fn *get_token;
|
||||
|
||||
void *get_token_user_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Options necessary to create a (synchronous) ntlm authentication proxy strategy
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_ntlm_options {
|
||||
|
||||
aws_http_proxy_negotiation_get_token_sync_fn *get_token;
|
||||
|
||||
aws_http_proxy_negotiation_get_challenge_token_sync_fn *get_challenge_token;
|
||||
|
||||
void *get_challenge_token_user_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Options necessary to create an adaptive sequential strategy that tries one or more of kerberos and ntlm (in that
|
||||
* order, if both are active). If an options struct is NULL, then that strategy will not be used.
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_adaptive_options {
|
||||
/*
|
||||
* If non-null, will insert a kerberos proxy strategy into the adaptive sequence
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_kerberos_options *kerberos_options;
|
||||
|
||||
/*
|
||||
* If non-null will insert an ntlm proxy strategy into the adaptive sequence
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_ntlm_options *ntlm_options;
|
||||
};
|
||||
|
||||
/*
|
||||
* Options necessary to create a sequential proxy strategy.
|
||||
*/
|
||||
struct aws_http_proxy_strategy_tunneling_sequence_options {
|
||||
struct aws_http_proxy_strategy **strategies;
|
||||
|
||||
uint32_t strategy_count;
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Take a reference to an http proxy negotiator
|
||||
* @param proxy_negotiator negotiator to take a reference to
|
||||
* @return the strategy
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_negotiator *aws_http_proxy_negotiator_acquire(struct aws_http_proxy_negotiator *proxy_negotiator);
|
||||
|
||||
/**
|
||||
* Release a reference to an http proxy negotiator
|
||||
* @param proxy_negotiator negotiator to release a reference to
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_proxy_negotiator_release(struct aws_http_proxy_negotiator *proxy_negotiator);
|
||||
|
||||
/**
|
||||
* Creates a new proxy negotiator from a proxy strategy
|
||||
* @param allocator memory allocator to use
|
||||
* @param strategy strategy to creation a new negotiator for
|
||||
* @return a new proxy negotiator if successful, otherwise NULL
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_negotiator *aws_http_proxy_strategy_create_negotiator(
|
||||
struct aws_http_proxy_strategy *strategy,
|
||||
struct aws_allocator *allocator);
|
||||
|
||||
/**
|
||||
* Take a reference to an http proxy strategy
|
||||
* @param proxy_strategy strategy to take a reference to
|
||||
* @return the strategy
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_strategy *aws_http_proxy_strategy_acquire(struct aws_http_proxy_strategy *proxy_strategy);
|
||||
|
||||
/**
|
||||
* Release a reference to an http proxy strategy
|
||||
* @param proxy_strategy strategy to release a reference to
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_proxy_strategy_release(struct aws_http_proxy_strategy *proxy_strategy);
|
||||
|
||||
/**
|
||||
* A constructor for a proxy strategy that performs basic authentication by adding the appropriate
|
||||
* header and header value to requests or CONNECT requests.
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param config basic authentication configuration info
|
||||
* @return a new proxy strategy if successfully constructed, otherwise NULL
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_basic_auth(
|
||||
struct aws_allocator *allocator,
|
||||
struct aws_http_proxy_strategy_basic_auth_options *config);
|
||||
|
||||
/**
|
||||
* Constructor for an adaptive tunneling proxy strategy. This strategy attempts a vanilla CONNECT and if that
|
||||
* fails it may make followup CONNECT attempts using kerberos or ntlm tokens, based on configuration and proxy
|
||||
* response properties.
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param config configuration options for the strategy
|
||||
* @return a new proxy strategy if successfully constructed, otherwise NULL
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_tunneling_adaptive(
|
||||
struct aws_allocator *allocator,
|
||||
struct aws_http_proxy_strategy_tunneling_adaptive_options *config);
|
||||
|
||||
/*
|
||||
* aws_http_proxy_config is the persistent, memory-managed version of aws_http_proxy_options
|
||||
*
|
||||
* This is a set of APIs for creating, destroying and converting between them
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a persistent proxy configuration from http connection options
|
||||
* @param allocator memory allocator to use
|
||||
* @param options http connection options to source proxy configuration from
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_from_connection_options(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_client_connection_options *options);
|
||||
|
||||
/**
|
||||
* Create a persistent proxy configuration from http connection manager options
|
||||
* @param allocator memory allocator to use
|
||||
* @param options http connection manager options to source proxy configuration from
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_from_manager_options(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_connection_manager_options *options);
|
||||
|
||||
/**
|
||||
* Create a persistent proxy configuration from non-persistent proxy options. The resulting
|
||||
* proxy configuration assumes a tunneling connection type.
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param options http proxy options to source proxy configuration from
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_tunneling_from_proxy_options(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_proxy_options *options);
|
||||
|
||||
/**
|
||||
* Create a persistent proxy configuration from non-persistent proxy options.
|
||||
* Legacy connection type of proxy options will be rejected.
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param options http proxy options to source proxy configuration from
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_proxy_options *options);
|
||||
|
||||
/**
|
||||
* Create a persistent proxy configuration from non-persistent proxy options.
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param options http proxy options to source proxy configuration from
|
||||
* @param is_tls_connection tls connection info of the main connection to determine connection_type
|
||||
* when the connection_type is legacy.
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options_with_tls_info(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_proxy_options *proxy_options,
|
||||
bool is_tls_connection);
|
||||
|
||||
/**
|
||||
* Clones an existing proxy configuration. A refactor could remove this (do a "move" between the old and new user
|
||||
* data in the one spot it's used) but that should wait until we have better test cases for the logic where this
|
||||
* gets invoked (ntlm/kerberos chains).
|
||||
*
|
||||
* @param allocator memory allocator to use
|
||||
* @param proxy_config http proxy configuration to clone
|
||||
* @return
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_proxy_config *aws_http_proxy_config_new_clone(
|
||||
struct aws_allocator *allocator,
|
||||
const struct aws_http_proxy_config *proxy_config);
|
||||
|
||||
/**
|
||||
* Destroys an http proxy configuration
|
||||
* @param config http proxy configuration to destroy
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_proxy_config_destroy(struct aws_http_proxy_config *config);
|
||||
|
||||
/**
|
||||
* Initializes non-persistent http proxy options from a persistent http proxy configuration
|
||||
* @param options http proxy options to initialize
|
||||
* @param config the http proxy config to use as an initialization source
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_proxy_options_init_from_config(
|
||||
struct aws_http_proxy_options *options,
|
||||
const struct aws_http_proxy_config *config);
|
||||
|
||||
/**
|
||||
* Establish an arbitrary protocol connection through an http proxy via tunneling CONNECT. Alpn is
|
||||
* not required for this connection process to succeed, but we encourage its use if available.
|
||||
*
|
||||
* @param channel_options configuration options for the socket level connection
|
||||
* @param proxy_options configuration options for the proxy connection
|
||||
*
|
||||
* @return AWS_OP_SUCCESS if the asynchronous channel kickoff succeeded, AWS_OP_ERR otherwise
|
||||
*/
|
||||
AWS_HTTP_API int aws_http_proxy_new_socket_channel(
|
||||
struct aws_socket_channel_bootstrap_options *channel_options,
|
||||
const struct aws_http_proxy_options *proxy_options);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_PROXY_STRATEGY_H */
|
||||
File diff suppressed because it is too large
Load Diff
212
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/server.h
Normal file
212
Plugins/GameLiftPlugin/Source/AWSSDK/Include/aws/http/server.h
Normal file
@@ -0,0 +1,212 @@
|
||||
#ifndef AWS_HTTP_SERVER_H
|
||||
#define AWS_HTTP_SERVER_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_http_connection;
|
||||
struct aws_server_bootstrap;
|
||||
struct aws_socket_options;
|
||||
struct aws_tls_connection_options;
|
||||
/**
|
||||
* A listening socket which accepts incoming HTTP connections,
|
||||
* creating a server-side aws_http_connection to handle each one.
|
||||
*/
|
||||
struct aws_http_server;
|
||||
struct aws_http_stream;
|
||||
|
||||
typedef void(aws_http_server_on_incoming_connection_fn)(
|
||||
struct aws_http_server *server,
|
||||
struct aws_http_connection *connection,
|
||||
int error_code,
|
||||
void *user_data);
|
||||
|
||||
typedef void(aws_http_server_on_destroy_fn)(void *user_data);
|
||||
|
||||
/**
|
||||
* Options for creating an HTTP server.
|
||||
* Initialize with AWS_HTTP_SERVER_OPTIONS_INIT to set default values.
|
||||
*/
|
||||
struct aws_http_server_options {
|
||||
/**
|
||||
* The sizeof() this struct, used for versioning.
|
||||
* Set by AWS_HTTP_SERVER_OPTIONS_INIT.
|
||||
*/
|
||||
size_t self_size;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* Must outlive server.
|
||||
*/
|
||||
struct aws_allocator *allocator;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* Must outlive server.
|
||||
*/
|
||||
struct aws_server_bootstrap *bootstrap;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* Server makes copy.
|
||||
*/
|
||||
struct aws_socket_endpoint *endpoint;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* Server makes a copy.
|
||||
*/
|
||||
struct aws_socket_options *socket_options;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Server copies all contents except the `aws_tls_ctx`, which must outlive the server.
|
||||
*/
|
||||
struct aws_tls_connection_options *tls_options;
|
||||
|
||||
/**
|
||||
* Initial window size for incoming connections.
|
||||
* Optional.
|
||||
* A default size is set by AWS_HTTP_SERVER_OPTIONS_INIT.
|
||||
*/
|
||||
size_t initial_window_size;
|
||||
|
||||
/**
|
||||
* User data passed to callbacks.
|
||||
* Optional.
|
||||
*/
|
||||
void *server_user_data;
|
||||
|
||||
/**
|
||||
* Invoked when an incoming connection has been set up, or when setup has failed.
|
||||
* Required.
|
||||
* If setup succeeds, the user must call aws_http_connection_configure_server().
|
||||
*/
|
||||
aws_http_server_on_incoming_connection_fn *on_incoming_connection;
|
||||
|
||||
/**
|
||||
* Invoked when the server finishes the destroy operation.
|
||||
* Optional.
|
||||
*/
|
||||
aws_http_server_on_destroy_fn *on_destroy_complete;
|
||||
|
||||
/**
|
||||
* Set to true to manually manage the read window size.
|
||||
*
|
||||
* If this is false, the connection will maintain a constant window size.
|
||||
*
|
||||
* If this is true, the caller must manually increment the window size using aws_http_stream_update_window().
|
||||
* If the window is not incremented, it will shrink by the amount of body data received. If the window size
|
||||
* reaches 0, no further data will be received.
|
||||
**/
|
||||
bool manual_window_management;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes aws_http_server_options with default values.
|
||||
*/
|
||||
#define AWS_HTTP_SERVER_OPTIONS_INIT \
|
||||
{ \
|
||||
.self_size = sizeof(struct aws_http_server_options), \
|
||||
.initial_window_size = SIZE_MAX, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked at the start of an incoming request.
|
||||
* To process the request, the user must create a request handler stream and return it to the connection.
|
||||
* If NULL is returned, the request will not be processed and the last error will be reported as the reason for failure.
|
||||
*/
|
||||
typedef struct aws_http_stream *(aws_http_on_incoming_request_fn)(struct aws_http_connection *connection,
|
||||
void *user_data);
|
||||
|
||||
typedef void(aws_http_on_server_connection_shutdown_fn)(
|
||||
struct aws_http_connection *connection,
|
||||
int error_code,
|
||||
void *connection_user_data);
|
||||
|
||||
/**
|
||||
* Options for configuring a server-side aws_http_connection.
|
||||
* Initialized with AWS_HTTP_SERVER_CONNECTION_OPTIONS_INIT to set default values.
|
||||
*/
|
||||
struct aws_http_server_connection_options {
|
||||
/**
|
||||
* The sizeof() this struct, used for versioning.
|
||||
* Set by AWS_HTTP_SERVER_CONNECTION_OPTIONS_INIT.
|
||||
*/
|
||||
size_t self_size;
|
||||
|
||||
/**
|
||||
* User data specific to this connection.
|
||||
* Optional.
|
||||
*/
|
||||
void *connection_user_data;
|
||||
|
||||
/**
|
||||
* Invoked at the start of an incoming request.
|
||||
* Required.
|
||||
* The user must create a request handler stream and return it to the connection.
|
||||
* See `aws_http_on_incoming_request_fn`.
|
||||
*/
|
||||
aws_http_on_incoming_request_fn *on_incoming_request;
|
||||
|
||||
/**
|
||||
* Invoked when the connection is shut down.
|
||||
* Optional.
|
||||
*/
|
||||
aws_http_on_server_connection_shutdown_fn *on_shutdown;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes aws_http_server_connection_options with default values.
|
||||
*/
|
||||
#define AWS_HTTP_SERVER_CONNECTION_OPTIONS_INIT \
|
||||
{ \
|
||||
.self_size = sizeof(struct aws_http_server_connection_options), \
|
||||
}
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Create server, a listening socket that accepts incoming connections.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_server *aws_http_server_new(const struct aws_http_server_options *options);
|
||||
|
||||
/**
|
||||
* Release the server. It will close the listening socket and all the connections existing in the server.
|
||||
* The on_destroy_complete will be invoked when the destroy operation completes
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_http_server_release(struct aws_http_server *server);
|
||||
|
||||
/**
|
||||
* Configure a server connection.
|
||||
* This must be called from the server's on_incoming_connection callback.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_http_connection_configure_server(
|
||||
struct aws_http_connection *connection,
|
||||
const struct aws_http_server_connection_options *options);
|
||||
|
||||
/**
|
||||
* Returns true if this is a server connection.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
bool aws_http_connection_is_server(const struct aws_http_connection *connection);
|
||||
|
||||
/**
|
||||
* Returns the local listener endpoint of the HTTP server. Only valid as long as the server remains valid.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
const struct aws_socket_endpoint *aws_http_server_get_listener_endpoint(const struct aws_http_server *server);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_SERVER_H */
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef AWS_HTTP_STATISTICS_H
|
||||
#define AWS_HTTP_STATISTICS_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
#include <aws/common/statistics.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
enum aws_crt_http_statistics_category {
|
||||
AWSCRT_STAT_CAT_HTTP1_CHANNEL = AWS_CRT_STATISTICS_CATEGORY_BEGIN_RANGE(AWS_C_HTTP_PACKAGE_ID),
|
||||
AWSCRT_STAT_CAT_HTTP2_CHANNEL,
|
||||
};
|
||||
|
||||
/**
|
||||
* A statistics struct for http handlers. Tracks the actual amount of time that incoming and outgoing requests are
|
||||
* waiting for their IO to complete.
|
||||
*/
|
||||
struct aws_crt_statistics_http1_channel {
|
||||
aws_crt_statistics_category_t category;
|
||||
|
||||
uint64_t pending_outgoing_stream_ms;
|
||||
uint64_t pending_incoming_stream_ms;
|
||||
|
||||
uint32_t current_outgoing_stream_id;
|
||||
uint32_t current_incoming_stream_id;
|
||||
};
|
||||
|
||||
struct aws_crt_statistics_http2_channel {
|
||||
aws_crt_statistics_category_t category;
|
||||
|
||||
uint64_t pending_outgoing_stream_ms;
|
||||
uint64_t pending_incoming_stream_ms;
|
||||
|
||||
/* True if during the time of report, there has ever been no active streams on the connection */
|
||||
bool was_inactive;
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Initializes a http channel handler statistics struct
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_crt_statistics_http1_channel_init(struct aws_crt_statistics_http1_channel *stats);
|
||||
|
||||
/**
|
||||
* Cleans up a http channel handler statistics struct
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_crt_statistics_http1_channel_cleanup(struct aws_crt_statistics_http1_channel *stats);
|
||||
|
||||
/**
|
||||
* Resets a http channel handler statistics struct's statistics
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_crt_statistics_http1_channel_reset(struct aws_crt_statistics_http1_channel *stats);
|
||||
|
||||
/**
|
||||
* Initializes a HTTP/2 channel handler statistics struct
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_crt_statistics_http2_channel_init(struct aws_crt_statistics_http2_channel *stats);
|
||||
/**
|
||||
* Resets a HTTP/2 channel handler statistics struct's statistics
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_crt_statistics_http2_channel_reset(struct aws_crt_statistics_http2_channel *stats);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_STATISTICS_H */
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef AWS_HTTP_STATUS_CODE_H
|
||||
#define AWS_HTTP_STATUS_CODE_H
|
||||
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define most of the http response codes we probably will use.
|
||||
* https://www.iana.org/assignments/http-status-codes/http-status-codes.txt
|
||||
* This is NOT a definitive list of codes.
|
||||
*/
|
||||
enum aws_http_status_code {
|
||||
/*
|
||||
* This is a special response code defined for convenience in error processing,
|
||||
* indicating processing of http request met error and didn't reach server.
|
||||
*/
|
||||
AWS_HTTP_STATUS_CODE_UNKNOWN = -1,
|
||||
AWS_HTTP_STATUS_CODE_100_CONTINUE = 100,
|
||||
AWS_HTTP_STATUS_CODE_101_SWITCHING_PROTOCOLS = 101,
|
||||
AWS_HTTP_STATUS_CODE_102_PROCESSING = 102,
|
||||
AWS_HTTP_STATUS_CODE_103_EARLY_HINTS = 103,
|
||||
AWS_HTTP_STATUS_CODE_200_OK = 200,
|
||||
AWS_HTTP_STATUS_CODE_201_CREATED = 201,
|
||||
AWS_HTTP_STATUS_CODE_202_ACCEPTED = 202,
|
||||
AWS_HTTP_STATUS_CODE_203_NON_AUTHORITATIVE_INFORMATION = 203,
|
||||
AWS_HTTP_STATUS_CODE_204_NO_CONTENT = 204,
|
||||
AWS_HTTP_STATUS_CODE_205_RESET_CONTENT = 205,
|
||||
AWS_HTTP_STATUS_CODE_206_PARTIAL_CONTENT = 206,
|
||||
AWS_HTTP_STATUS_CODE_207_MULTI_STATUS = 207,
|
||||
AWS_HTTP_STATUS_CODE_208_ALREADY_REPORTED = 208,
|
||||
AWS_HTTP_STATUS_CODE_226_IM_USED = 226,
|
||||
AWS_HTTP_STATUS_CODE_300_MULTIPLE_CHOICES = 300,
|
||||
AWS_HTTP_STATUS_CODE_301_MOVED_PERMANENTLY = 301,
|
||||
AWS_HTTP_STATUS_CODE_302_FOUND = 302,
|
||||
AWS_HTTP_STATUS_CODE_303_SEE_OTHER = 303,
|
||||
AWS_HTTP_STATUS_CODE_304_NOT_MODIFIED = 304,
|
||||
AWS_HTTP_STATUS_CODE_305_USE_PROXY = 305,
|
||||
AWS_HTTP_STATUS_CODE_307_TEMPORARY_REDIRECT = 307,
|
||||
AWS_HTTP_STATUS_CODE_308_PERMANENT_REDIRECT = 308,
|
||||
AWS_HTTP_STATUS_CODE_400_BAD_REQUEST = 400,
|
||||
AWS_HTTP_STATUS_CODE_401_UNAUTHORIZED = 401,
|
||||
AWS_HTTP_STATUS_CODE_402_PAYMENT_REQUIRED = 402,
|
||||
AWS_HTTP_STATUS_CODE_403_FORBIDDEN = 403,
|
||||
AWS_HTTP_STATUS_CODE_404_NOT_FOUND = 404,
|
||||
AWS_HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED = 405,
|
||||
AWS_HTTP_STATUS_CODE_406_NOT_ACCEPTABLE = 406,
|
||||
AWS_HTTP_STATUS_CODE_407_PROXY_AUTHENTICATION_REQUIRED = 407,
|
||||
AWS_HTTP_STATUS_CODE_408_REQUEST_TIMEOUT = 408,
|
||||
AWS_HTTP_STATUS_CODE_409_CONFLICT = 409,
|
||||
AWS_HTTP_STATUS_CODE_410_GONE = 410,
|
||||
AWS_HTTP_STATUS_CODE_411_LENGTH_REQUIRED = 411,
|
||||
AWS_HTTP_STATUS_CODE_412_PRECONDITION_FAILED = 412,
|
||||
AWS_HTTP_STATUS_CODE_413_REQUEST_ENTITY_TOO_LARGE = 413,
|
||||
AWS_HTTP_STATUS_CODE_414_REQUEST_URI_TOO_LONG = 414,
|
||||
AWS_HTTP_STATUS_CODE_415_UNSUPPORTED_MEDIA_TYPE = 415,
|
||||
AWS_HTTP_STATUS_CODE_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
||||
AWS_HTTP_STATUS_CODE_417_EXPECTATION_FAILED = 417,
|
||||
AWS_HTTP_STATUS_CODE_421_MISDIRECTED_REQUEST = 421,
|
||||
AWS_HTTP_STATUS_CODE_422_UNPROCESSABLE_ENTITY = 422,
|
||||
AWS_HTTP_STATUS_CODE_423_LOCKED = 423,
|
||||
AWS_HTTP_STATUS_CODE_424_FAILED_DEPENDENCY = 424,
|
||||
AWS_HTTP_STATUS_CODE_425_TOO_EARLY = 425,
|
||||
AWS_HTTP_STATUS_CODE_426_UPGRADE_REQUIRED = 426,
|
||||
AWS_HTTP_STATUS_CODE_428_PRECONDITION_REQUIRED = 428,
|
||||
AWS_HTTP_STATUS_CODE_429_TOO_MANY_REQUESTS = 429,
|
||||
AWS_HTTP_STATUS_CODE_431_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
||||
AWS_HTTP_STATUS_CODE_451_UNAVAILABLE_FOR_LEGAL_REASON = 451,
|
||||
AWS_HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR = 500,
|
||||
AWS_HTTP_STATUS_CODE_501_NOT_IMPLEMENTED = 501,
|
||||
AWS_HTTP_STATUS_CODE_502_BAD_GATEWAY = 502,
|
||||
AWS_HTTP_STATUS_CODE_503_SERVICE_UNAVAILABLE = 503,
|
||||
AWS_HTTP_STATUS_CODE_504_GATEWAY_TIMEOUT = 504,
|
||||
AWS_HTTP_STATUS_CODE_505_HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
AWS_HTTP_STATUS_CODE_506_VARIANT_ALSO_NEGOTIATES = 506,
|
||||
AWS_HTTP_STATUS_CODE_507_INSUFFICIENT_STORAGE = 507,
|
||||
AWS_HTTP_STATUS_CODE_508_LOOP_DETECTED = 508,
|
||||
AWS_HTTP_STATUS_CODE_510_NOT_EXTENDED = 510,
|
||||
AWS_HTTP_STATUS_CODE_511_NETWORK_AUTHENTICATION_REQUIRED = 511,
|
||||
};
|
||||
#endif /* AWS_HTTP_STATUS_CODE_H */
|
||||
@@ -0,0 +1,492 @@
|
||||
#ifndef AWS_HTTP_WEBSOCKET_H
|
||||
#define AWS_HTTP_WEBSOCKET_H
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include <aws/http/http.h>
|
||||
|
||||
AWS_PUSH_SANE_WARNING_LEVEL
|
||||
|
||||
struct aws_http_header;
|
||||
struct aws_http_message;
|
||||
|
||||
/* TODO: Document lifetime stuff */
|
||||
/* TODO: Document CLOSE frame behavior (when auto-sent during close, when auto-closed) */
|
||||
/* TODO: Accept payload as aws_input_stream */
|
||||
|
||||
/**
|
||||
* A websocket connection.
|
||||
*/
|
||||
struct aws_websocket;
|
||||
|
||||
/**
|
||||
* Opcode describing the type of a websocket frame.
|
||||
* RFC-6455 Section 5.2
|
||||
*/
|
||||
enum aws_websocket_opcode {
|
||||
AWS_WEBSOCKET_OPCODE_CONTINUATION = 0x0,
|
||||
AWS_WEBSOCKET_OPCODE_TEXT = 0x1,
|
||||
AWS_WEBSOCKET_OPCODE_BINARY = 0x2,
|
||||
AWS_WEBSOCKET_OPCODE_CLOSE = 0x8,
|
||||
AWS_WEBSOCKET_OPCODE_PING = 0x9,
|
||||
AWS_WEBSOCKET_OPCODE_PONG = 0xA,
|
||||
};
|
||||
|
||||
#define AWS_WEBSOCKET_MAX_PAYLOAD_LENGTH 0x7FFFFFFFFFFFFFFF
|
||||
#define AWS_WEBSOCKET_MAX_HANDSHAKE_KEY_LENGTH 25
|
||||
#define AWS_WEBSOCKET_CLOSE_TIMEOUT 1000000000 // nanos -> 1 sec
|
||||
|
||||
/**
|
||||
* Data passed to the websocket on_connection_setup callback.
|
||||
*
|
||||
* An error_code of zero indicates that setup was completely successful.
|
||||
* You own the websocket pointer now and must call aws_websocket_release() when you are done with it.
|
||||
* You can inspect the response headers, if you're interested.
|
||||
*
|
||||
* A non-zero error_code indicates that setup failed.
|
||||
* The websocket pointer will be NULL.
|
||||
* If the server sent a response, you can inspect its status-code, headers, and body,
|
||||
* but this data will NULL if setup failed before a full response could be received.
|
||||
* If you wish to persist data from the response make a deep copy.
|
||||
* The response data becomes invalid once the callback completes.
|
||||
*/
|
||||
struct aws_websocket_on_connection_setup_data {
|
||||
int error_code;
|
||||
struct aws_websocket *websocket;
|
||||
const int *handshake_response_status;
|
||||
const struct aws_http_header *handshake_response_header_array;
|
||||
size_t num_handshake_response_headers;
|
||||
const struct aws_byte_cursor *handshake_response_body;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when websocket setup is complete.
|
||||
* Called exactly once on the websocket's event-loop thread.
|
||||
* See `aws_websocket_on_connection_setup_data`.
|
||||
*/
|
||||
typedef void(
|
||||
aws_websocket_on_connection_setup_fn)(const struct aws_websocket_on_connection_setup_data *setup, void *user_data);
|
||||
|
||||
/**
|
||||
* Called when the websocket has finished shutting down.
|
||||
* Called once on the websocket's event-loop thread if setup succeeded.
|
||||
* If setup failed, this is never called.
|
||||
*/
|
||||
typedef void(aws_websocket_on_connection_shutdown_fn)(struct aws_websocket *websocket, int error_code, void *user_data);
|
||||
|
||||
/**
|
||||
* Data about an incoming frame.
|
||||
* See RFC-6455 Section 5.2.
|
||||
*/
|
||||
struct aws_websocket_incoming_frame {
|
||||
uint64_t payload_length;
|
||||
uint8_t opcode;
|
||||
bool fin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when a new frame arrives.
|
||||
* Invoked once per frame on the websocket's event-loop thread.
|
||||
* Each incoming-frame-begin call will eventually be followed by an incoming-frame-complete call,
|
||||
* before the next frame begins and before the websocket shuts down.
|
||||
*
|
||||
* Return true to proceed normally. If false is returned, the websocket will read no further data,
|
||||
* the frame will complete with an error-code, and the connection will close.
|
||||
*/
|
||||
typedef bool(aws_websocket_on_incoming_frame_begin_fn)(
|
||||
struct aws_websocket *websocket,
|
||||
const struct aws_websocket_incoming_frame *frame,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Called repeatedly as payload data arrives.
|
||||
* Invoked 0 or more times on the websocket's event-loop thread.
|
||||
* Payload data will not be valid after this call, so copy if necessary.
|
||||
* The payload data is always unmasked at this point.
|
||||
*
|
||||
* NOTE: If you created the websocket with `manual_window_management` set true, you must maintain the read window.
|
||||
* Whenever the read window reaches 0, you will stop receiving anything.
|
||||
* The websocket's `initial_window_size` determines the starting size of the read window.
|
||||
* The read window shrinks as you receive the payload from "data" frames (TEXT, BINARY, and CONTINUATION).
|
||||
* Use aws_websocket_increment_read_window() to increment the window again and keep frames flowing.
|
||||
* Maintain a larger window to keep up high throughput.
|
||||
* You only need to worry about the payload from "data" frames.
|
||||
* The websocket automatically increments the window to account for any
|
||||
* other incoming bytes, including other parts of a frame (opcode, payload-length, etc)
|
||||
* and the payload of other frame types (PING, PONG, CLOSE).
|
||||
*
|
||||
* Return true to proceed normally. If false is returned, the websocket will read no further data,
|
||||
* the frame will complete with an error-code, and the connection will close.
|
||||
*/
|
||||
typedef bool(aws_websocket_on_incoming_frame_payload_fn)(
|
||||
struct aws_websocket *websocket,
|
||||
const struct aws_websocket_incoming_frame *frame,
|
||||
struct aws_byte_cursor data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Called when done processing an incoming frame.
|
||||
* If error_code is non-zero, an error occurred and the payload may not have been completely received.
|
||||
* Invoked once per frame on the websocket's event-loop thread.
|
||||
*
|
||||
* Return true to proceed normally. If false is returned, the websocket will read no further data
|
||||
* and the connection will close.
|
||||
*/
|
||||
typedef bool(aws_websocket_on_incoming_frame_complete_fn)(
|
||||
struct aws_websocket *websocket,
|
||||
const struct aws_websocket_incoming_frame *frame,
|
||||
int error_code,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Options for creating a websocket client connection.
|
||||
*/
|
||||
struct aws_websocket_client_connection_options {
|
||||
/**
|
||||
* Required.
|
||||
* Must outlive the connection.
|
||||
*/
|
||||
struct aws_allocator *allocator;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* The connection keeps the bootstrap alive via ref-counting.
|
||||
*/
|
||||
struct aws_client_bootstrap *bootstrap;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* aws_websocket_client_connect() makes a copy.
|
||||
*/
|
||||
const struct aws_socket_options *socket_options;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* aws_websocket_client_connect() deep-copies all contents,
|
||||
* and keeps the `aws_tls_ctx` alive via ref-counting.
|
||||
*/
|
||||
const struct aws_tls_connection_options *tls_options;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Configuration options related to http proxy usage.
|
||||
*/
|
||||
const struct aws_http_proxy_options *proxy_options;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* aws_websocket_client_connect() makes a copy.
|
||||
*/
|
||||
struct aws_byte_cursor host;
|
||||
|
||||
/**
|
||||
* Optional.
|
||||
* Defaults to 443 if tls_options is present, 80 if it is not.
|
||||
*/
|
||||
uint32_t port;
|
||||
|
||||
/**
|
||||
* Required.
|
||||
* The request will be kept alive via ref-counting until the handshake completes.
|
||||
* Suggestion: create via aws_http_message_new_websocket_handshake_request()
|
||||
*
|
||||
* The method MUST be set to GET.
|
||||
* The following headers are required (replace values in []):
|
||||
*
|
||||
* Host: [server.example.com]
|
||||
* Upgrade: websocket
|
||||
* Connection: Upgrade
|
||||
* Sec-WebSocket-Key: [dGhlIHNhbXBsZSBub25jZQ==]
|
||||
* Sec-WebSocket-Version: 13
|
||||
*
|
||||
* Sec-Websocket-Key should be a random 16 bytes value, Base64 encoded.
|
||||
*/
|
||||
struct aws_http_message *handshake_request;
|
||||
|
||||
/**
|
||||
* Initial size of the websocket's read window.
|
||||
* Ignored unless `manual_window_management` is true.
|
||||
* Set to 0 to prevent any incoming websocket frames until aws_websocket_increment_read_window() is called.
|
||||
*/
|
||||
size_t initial_window_size;
|
||||
|
||||
/**
|
||||
* User data for callbacks.
|
||||
* Optional.
|
||||
*/
|
||||
void *user_data;
|
||||
|
||||
/**
|
||||
* Called when connect completes.
|
||||
* Required.
|
||||
* If unsuccessful, error_code will be set, connection will be NULL,
|
||||
* and the on_connection_shutdown callback will never be called.
|
||||
* If successful, the user is now responsible for the websocket and must
|
||||
* call aws_websocket_release() when they are done with it.
|
||||
*/
|
||||
aws_websocket_on_connection_setup_fn *on_connection_setup;
|
||||
|
||||
/**
|
||||
* Called when connection has finished shutting down.
|
||||
* Optional.
|
||||
* Never called if `on_connection_setup` reported failure.
|
||||
* Note that the connection is not completely done until `on_connection_shutdown` has been called
|
||||
* AND aws_websocket_release() has been called.
|
||||
*/
|
||||
aws_websocket_on_connection_shutdown_fn *on_connection_shutdown;
|
||||
|
||||
/**
|
||||
* Called when each new frame arrives.
|
||||
* Optional.
|
||||
* See `aws_websocket_on_incoming_frame_begin_fn`.
|
||||
*/
|
||||
aws_websocket_on_incoming_frame_begin_fn *on_incoming_frame_begin;
|
||||
|
||||
/**
|
||||
* Called repeatedly as payload data arrives.
|
||||
* Optional.
|
||||
* See `aws_websocket_on_incoming_frame_payload_fn`.
|
||||
*/
|
||||
aws_websocket_on_incoming_frame_payload_fn *on_incoming_frame_payload;
|
||||
|
||||
/**
|
||||
* Called when done processing an incoming frame.
|
||||
* Optional.
|
||||
* See `aws_websocket_on_incoming_frame_complete_fn`.
|
||||
*/
|
||||
aws_websocket_on_incoming_frame_complete_fn *on_incoming_frame_complete;
|
||||
|
||||
/**
|
||||
* Set to true to manually manage the read window size.
|
||||
*
|
||||
* If this is false, no backpressure is applied and frames will arrive as fast as possible.
|
||||
*
|
||||
* If this is true, then whenever the read window reaches 0 you will stop receiving anything.
|
||||
* The websocket's `initial_window_size` determines the starting size of the read window.
|
||||
* The read window shrinks as you receive the payload from "data" frames (TEXT, BINARY, and CONTINUATION).
|
||||
* Use aws_websocket_increment_read_window() to increment the window again and keep frames flowing.
|
||||
* Maintain a larger window to keep up high throughput.
|
||||
* You only need to worry about the payload from "data" frames.
|
||||
* The websocket automatically increments the window to account for any
|
||||
* other incoming bytes, including other parts of a frame (opcode, payload-length, etc)
|
||||
* and the payload of other frame types (PING, PONG, CLOSE).
|
||||
*/
|
||||
bool manual_window_management;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* If set, requests that a specific event loop be used to seat the connection, rather than the next one
|
||||
* in the event loop group. Useful for serializing all io and external events related to a client onto
|
||||
* a single thread.
|
||||
*/
|
||||
struct aws_event_loop *requested_event_loop;
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* Host resolution override that allows the user to override DNS behavior for this particular connection.
|
||||
*/
|
||||
const struct aws_host_resolution_config *host_resolution_config;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called repeatedly as the websocket's payload is streamed out.
|
||||
* The user should write payload data to out_buf, up to available capacity.
|
||||
* The websocket will mask this data for you, if necessary.
|
||||
* Invoked repeatedly on the websocket's event-loop thread.
|
||||
*
|
||||
* Return true to proceed normally. If false is returned, the websocket will send no further data,
|
||||
* the frame will complete with an error-code, and the connection will close.
|
||||
*/
|
||||
typedef bool(aws_websocket_stream_outgoing_payload_fn)(
|
||||
struct aws_websocket *websocket,
|
||||
struct aws_byte_buf *out_buf,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Called when a aws_websocket_send_frame() operation completes.
|
||||
* error_code will be zero if the operation was successful.
|
||||
* "Success" does not guarantee that the peer actually received or processed the frame.
|
||||
* Invoked exactly once per sent frame on the websocket's event-loop thread.
|
||||
*/
|
||||
typedef void(
|
||||
aws_websocket_outgoing_frame_complete_fn)(struct aws_websocket *websocket, int error_code, void *user_data);
|
||||
|
||||
/**
|
||||
* Options for sending a websocket frame.
|
||||
* This structure is copied immediately by aws_websocket_send().
|
||||
* For descriptions of opcode, fin, and payload_length see in RFC-6455 Section 5.2.
|
||||
*/
|
||||
struct aws_websocket_send_frame_options {
|
||||
/**
|
||||
* Size of payload to be sent via `stream_outgoing_payload` callback.
|
||||
*/
|
||||
uint64_t payload_length;
|
||||
|
||||
/**
|
||||
* User data passed to callbacks.
|
||||
*/
|
||||
void *user_data;
|
||||
|
||||
/**
|
||||
* Callback for sending payload data.
|
||||
* See `aws_websocket_stream_outgoing_payload_fn`.
|
||||
* Required if `payload_length` is non-zero.
|
||||
*/
|
||||
aws_websocket_stream_outgoing_payload_fn *stream_outgoing_payload;
|
||||
|
||||
/**
|
||||
* Callback for completion of send operation.
|
||||
* See `aws_websocket_outgoing_frame_complete_fn`.
|
||||
* Optional.
|
||||
*/
|
||||
aws_websocket_outgoing_frame_complete_fn *on_complete;
|
||||
|
||||
/**
|
||||
* Frame type.
|
||||
* `aws_websocket_opcode` enum provides standard values.
|
||||
*/
|
||||
uint8_t opcode;
|
||||
|
||||
/**
|
||||
* Indicates that this is the final fragment in a message. The first fragment MAY also be the final fragment.
|
||||
*/
|
||||
bool fin;
|
||||
};
|
||||
|
||||
AWS_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Return true if opcode is for a data frame, false if opcode if for a control frame.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
bool aws_websocket_is_data_frame(uint8_t opcode);
|
||||
|
||||
/**
|
||||
* Asynchronously establish a client websocket connection.
|
||||
* The on_connection_setup callback is invoked when the operation has finished creating a connection, or failed.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_websocket_client_connect(const struct aws_websocket_client_connection_options *options);
|
||||
|
||||
/**
|
||||
* Increment the websocket's ref-count, preventing it from being destroyed.
|
||||
* @return Always returns the same pointer that is passed in.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_websocket *aws_websocket_acquire(struct aws_websocket *websocket);
|
||||
|
||||
/**
|
||||
* Decrement the websocket's ref-count.
|
||||
* When the ref-count reaches zero, the connection will shut down, if it hasn't already.
|
||||
* Users must release the websocket when they are done with it.
|
||||
* The websocket's memory cannot be reclaimed until this is done.
|
||||
* Callbacks may continue firing after this is called, with "shutdown" being the final callback.
|
||||
* This function may be called from any thread.
|
||||
*
|
||||
* It is safe to pass NULL, nothing will happen.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_websocket_release(struct aws_websocket *websocket);
|
||||
|
||||
/**
|
||||
* Close the websocket connection.
|
||||
* It is safe to call this, even if the connection is already closed or closing.
|
||||
* The websocket will attempt to send a CLOSE frame during normal shutdown.
|
||||
* If `free_scarce_resources_immediately` is true, the connection will be torn down as quickly as possible.
|
||||
* This function may be called from any thread.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_websocket_close(struct aws_websocket *websocket, bool free_scarce_resources_immediately);
|
||||
|
||||
/**
|
||||
* Send a websocket frame.
|
||||
* The `options` struct is copied.
|
||||
* A callback will be invoked when the operation completes.
|
||||
* This function may be called from any thread.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_websocket_send_frame(struct aws_websocket *websocket, const struct aws_websocket_send_frame_options *options);
|
||||
|
||||
/**
|
||||
* Manually increment the read window to keep frames flowing.
|
||||
*
|
||||
* If the websocket was created with `manual_window_management` set true,
|
||||
* then whenever the read window reaches 0 you will stop receiving data.
|
||||
* The websocket's `initial_window_size` determines the starting size of the read window.
|
||||
* The read window shrinks as you receive the payload from "data" frames (TEXT, BINARY, and CONTINUATION).
|
||||
* Use aws_websocket_increment_read_window() to increment the window again and keep frames flowing.
|
||||
* Maintain a larger window to keep up high throughput.
|
||||
* You only need to worry about the payload from "data" frames.
|
||||
* The websocket automatically increments the window to account for any
|
||||
* other incoming bytes, including other parts of a frame (opcode, payload-length, etc)
|
||||
* and the payload of other frame types (PING, PONG, CLOSE).
|
||||
*
|
||||
* If the websocket was created with `manual_window_management` set false, this function does nothing.
|
||||
*
|
||||
* This function may be called from any thread.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
void aws_websocket_increment_read_window(struct aws_websocket *websocket, size_t size);
|
||||
|
||||
/**
|
||||
* Convert the websocket into a mid-channel handler.
|
||||
* The websocket will stop being usable via its public API and become just another handler in the channel.
|
||||
* The caller will likely install a channel handler to the right.
|
||||
* This must not be called in the middle of an incoming frame (between "frame begin" and "frame complete" callbacks).
|
||||
* This MUST be called from the websocket's thread.
|
||||
*
|
||||
* If successful:
|
||||
* - Other than aws_websocket_release(), all calls to aws_websocket_x() functions are ignored.
|
||||
* - The websocket will no longer invoke any "incoming frame" callbacks.
|
||||
* - aws_io_messages written by a downstream handler will be wrapped in binary data frames and sent upstream.
|
||||
* The data may be split/combined as it is sent along.
|
||||
* - aws_io_messages read from upstream handlers will be scanned for binary data frames.
|
||||
* The payloads of these frames will be sent downstream.
|
||||
* The payloads may be split/combined as they are sent along.
|
||||
* - An incoming close frame will automatically result in channel-shutdown.
|
||||
* - aws_websocket_release() must still be called or the websocket and its channel will never be cleaned up.
|
||||
* - The websocket will still invoke its "on connection shutdown" callback when channel shutdown completes.
|
||||
*
|
||||
* If unsuccessful, NULL is returned and the websocket is unchanged.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_websocket_convert_to_midchannel_handler(struct aws_websocket *websocket);
|
||||
|
||||
/**
|
||||
* Returns the websocket's underlying I/O channel.
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_channel *aws_websocket_get_channel(const struct aws_websocket *websocket);
|
||||
|
||||
/**
|
||||
* Generate value for a Sec-WebSocket-Key header and write it into `dst` buffer.
|
||||
* The buffer should have at least AWS_WEBSOCKET_MAX_HANDSHAKE_KEY_LENGTH space available.
|
||||
*
|
||||
* This value is the base64 encoding of a random 16-byte value.
|
||||
* RFC-6455 Section 4.1
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
int aws_websocket_random_handshake_key(struct aws_byte_buf *dst);
|
||||
|
||||
/**
|
||||
* Create request with all required fields for a websocket upgrade request.
|
||||
* The method and path are set, and the the following headers are added:
|
||||
*
|
||||
* Host: <host>
|
||||
* Upgrade: websocket
|
||||
* Connection: Upgrade
|
||||
* Sec-WebSocket-Key: <base64 encoding of 16 random bytes>
|
||||
* Sec-WebSocket-Version: 13
|
||||
*/
|
||||
AWS_HTTP_API
|
||||
struct aws_http_message *aws_http_message_new_websocket_handshake_request(
|
||||
struct aws_allocator *allocator,
|
||||
struct aws_byte_cursor path,
|
||||
struct aws_byte_cursor host);
|
||||
|
||||
AWS_EXTERN_C_END
|
||||
AWS_POP_SANE_WARNING_LEVEL
|
||||
|
||||
#endif /* AWS_HTTP_WEBSOCKET_H */
|
||||
Reference in New Issue
Block a user