| 1 |
#ifndef AWS_HTTP_H1_ENCODER_H |
| 2 |
#define AWS_HTTP_H1_ENCODER_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <aws/http/private/http_impl.h> |
| 9 |
#include <aws/http/private/request_response_impl.h> |
| 10 |
|
| 11 |
struct aws_h1_data_write; |
| 12 |
|
| 13 |
struct aws_h1_chunk { |
| 14 |
struct aws_allocator *allocator; |
| 15 |
struct aws_input_stream *data; |
| 16 |
uint64_t data_size; |
| 17 |
aws_http1_stream_write_chunk_complete_fn *on_complete; |
| 18 |
void *user_data; |
| 19 |
struct aws_linked_list_node node; |
| 20 |
|
| 21 |
struct aws_byte_buf chunk_line; |
| 22 |
}; |
| 23 |
|
| 24 |
struct aws_h1_trailer { |
| 25 |
struct aws_allocator *allocator; |
| 26 |
struct aws_byte_buf trailer_data; |
| 27 |
}; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
struct aws_h1_encoder_message { |
| 34 |
|
| 35 |
struct aws_byte_buf outgoing_head_buf; |
| 36 |
|
| 37 |
struct aws_input_stream *body; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
struct aws_linked_list *pending_chunk_list; |
| 45 |
|
| 46 |
|
| 47 |
struct aws_h1_trailer *trailer; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
struct aws_linked_list *pending_data_write_list; |
| 52 |
|
| 53 |
|
| 54 |
struct aws_h1_data_write *current_data_write; |
| 55 |
|
| 56 |
|
| 57 |
uint64_t content_length; |
| 58 |
bool has_connection_close_header; |
| 59 |
bool has_chunked_encoding_header; |
| 60 |
bool has_manual_data_writes; |
| 61 |
}; |
| 62 |
|
| 63 |
enum aws_h1_encoder_state { |
| 64 |
AWS_H1_ENCODER_STATE_INIT, |
| 65 |
AWS_H1_ENCODER_STATE_HEAD, |
| 66 |
|
| 67 |
AWS_H1_ENCODER_STATE_UNCHUNKED_BODY_STREAM, |
| 68 |
|
| 69 |
AWS_H1_ENCODER_STATE_CHUNKED_BODY_STREAM, |
| 70 |
AWS_H1_ENCODER_STATE_CHUNKED_BODY_STREAM_LAST_CHUNK, |
| 71 |
|
| 72 |
AWS_H1_ENCODER_STATE_CHUNK_NEXT, |
| 73 |
AWS_H1_ENCODER_STATE_CHUNK_LINE, |
| 74 |
AWS_H1_ENCODER_STATE_CHUNK_BODY, |
| 75 |
AWS_H1_ENCODER_STATE_CHUNK_END, |
| 76 |
AWS_H1_ENCODER_STATE_CHUNK_TRAILER, |
| 77 |
|
| 78 |
AWS_H1_ENCODER_STATE_DATA_WRITE_NEXT, |
| 79 |
AWS_H1_ENCODER_STATE_DATA_WRITE_BODY, |
| 80 |
AWS_H1_ENCODER_STATE_DONE, |
| 81 |
}; |
| 82 |
|
| 83 |
struct aws_h1_encoder { |
| 84 |
struct aws_allocator *allocator; |
| 85 |
|
| 86 |
enum aws_h1_encoder_state state; |
| 87 |
|
| 88 |
struct aws_h1_encoder_message *message; |
| 89 |
|
| 90 |
uint64_t progress_bytes; |
| 91 |
|
| 92 |
struct aws_h1_chunk *current_chunk; |
| 93 |
|
| 94 |
uint64_t chunk_count; |
| 95 |
|
| 96 |
struct aws_http_stream *current_stream; |
| 97 |
}; |
| 98 |
|
| 99 |
struct aws_h1_chunk *aws_h1_chunk_new(struct aws_allocator *allocator, const struct aws_http1_chunk_options *options); |
| 100 |
struct aws_h1_trailer *aws_h1_trailer_new( |
| 101 |
struct aws_allocator *allocator, |
| 102 |
const struct aws_http_headers *trailing_headers); |
| 103 |
|
| 104 |
void aws_h1_trailer_destroy(struct aws_h1_trailer *trailer); |
| 105 |
|
| 106 |
|
| 107 |
void aws_h1_chunk_destroy(struct aws_h1_chunk *chunk); |
| 108 |
|
| 109 |
|
| 110 |
void aws_h1_chunk_complete_and_destroy(struct aws_h1_chunk *chunk, struct aws_http_stream *http_stream, int error_code); |
| 111 |
|
| 112 |
AWS_EXTERN_C_BEGIN |
| 113 |
|
| 114 |
|
| 115 |
AWS_HTTP_API |
| 116 |
int aws_h1_encoder_message_init_from_request( |
| 117 |
struct aws_h1_encoder_message *message, |
| 118 |
struct aws_allocator *allocator, |
| 119 |
const struct aws_http_message *request, |
| 120 |
struct aws_linked_list *pending_chunk_list, |
| 121 |
struct aws_linked_list *pending_data_write_list, |
| 122 |
bool use_manual_data_writes); |
| 123 |
|
| 124 |
int aws_h1_encoder_message_init_from_response( |
| 125 |
struct aws_h1_encoder_message *message, |
| 126 |
struct aws_allocator *allocator, |
| 127 |
const struct aws_http_message *response, |
| 128 |
bool body_headers_ignored, |
| 129 |
struct aws_linked_list *pending_chunk_list); |
| 130 |
|
| 131 |
AWS_HTTP_API |
| 132 |
void aws_h1_encoder_message_clean_up(struct aws_h1_encoder_message *message); |
| 133 |
|
| 134 |
AWS_HTTP_API |
| 135 |
void aws_h1_encoder_init(struct aws_h1_encoder *encoder, struct aws_allocator *allocator); |
| 136 |
|
| 137 |
AWS_HTTP_API |
| 138 |
void aws_h1_encoder_clean_up(struct aws_h1_encoder *encoder); |
| 139 |
|
| 140 |
AWS_HTTP_API |
| 141 |
int aws_h1_encoder_start_message( |
| 142 |
struct aws_h1_encoder *encoder, |
| 143 |
struct aws_h1_encoder_message *message, |
| 144 |
struct aws_http_stream *stream); |
| 145 |
|
| 146 |
AWS_HTTP_API |
| 147 |
int aws_h1_encoder_process(struct aws_h1_encoder *encoder, struct aws_byte_buf *out_buf); |
| 148 |
|
| 149 |
AWS_HTTP_API |
| 150 |
bool aws_h1_encoder_is_message_in_progress(const struct aws_h1_encoder *encoder); |
| 151 |
|
| 152 |
|
| 153 |
AWS_HTTP_API |
| 154 |
bool aws_h1_encoder_is_waiting_for_chunks(const struct aws_h1_encoder *encoder); |
| 155 |
|
| 156 |
|
| 157 |
AWS_HTTP_API |
| 158 |
bool aws_h1_encoder_is_waiting_for_data_writes(const struct aws_h1_encoder *encoder); |
| 159 |
|
| 160 |
AWS_EXTERN_C_END |
| 161 |
|
| 162 |
#endif |