1 #ifndef AWS_HTTP_REQUEST_RESPONSE_IMPL_H
2 #define AWS_HTTP_REQUEST_RESPONSE_IMPL_H
3 
4 /**
5  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6  * SPDX-License-Identifier: Apache-2.0.
7  */
8 
9 #include <aws/http/request_response.h>
10 
11 #include <aws/http/private/http_impl.h>
12 
13 #include <aws/common/atomics.h>
14 
15 struct aws_http_stream_vtable {
16     void (*destroy)(struct aws_http_stream *stream);
17     void (*update_window)(struct aws_http_stream *stream, size_t increment_size);
18     int (*activate)(struct aws_http_stream *stream);
19 
20     int (*http1_write_chunk)(struct aws_http_stream *http1_stream, const struct aws_http1_chunk_options *options);
21 
22     int (*http2_reset_stream)(struct aws_http_stream *http2_stream, uint32_t http2_error);
23     int (*http2_get_received_error_code)(struct aws_http_stream *http2_stream, uint32_t *http2_error);
24     int (*http2_get_sent_error_code)(struct aws_http_stream *http2_stream, uint32_t *http2_error);
25 };
26 
27 /**
28  * Base class for streams.
29  * There are specific implementations for each HTTP version.
30  */
31 struct aws_http_stream {
32     const struct aws_http_stream_vtable *vtable;
33     struct aws_allocator *alloc;
34     struct aws_http_connection *owning_connection;
35 
36     uint32_t id;
37 
38     void *user_data;
39     aws_http_on_incoming_headers_fn *on_incoming_headers;
40     aws_http_on_incoming_header_block_done_fn *on_incoming_header_block_done;
41     aws_http_on_incoming_body_fn *on_incoming_body;
42     aws_http_on_stream_complete_fn *on_complete;
43 
44     struct aws_atomic_var refcount;
45     enum aws_http_method request_method;
46 
47     union {
48         struct aws_http_stream_client_data {
49             int response_status;
50         } client;
51         struct aws_http_stream_server_data {
52             struct aws_byte_cursor request_method_str;
53             struct aws_byte_cursor request_path;
54             aws_http_on_incoming_request_done_fn *on_request_done;
55         } server;
56     } client_or_server_data;
57 
58     /* On client connections, `client_data` points to client_or_server_data.client and `server_data` is null.
59      * Opposite is true on server connections */
60     struct aws_http_stream_client_data *client_data;
61     struct aws_http_stream_server_data *server_data;
62 };
63 
64 #endif /* AWS_HTTP_REQUEST_RESPONSE_IMPL_H */
65