Deleted
Added
nxt_h1proto.c (628:02c472ca1c0f) | nxt_h1proto.c (629:b3e55c647741) |
---|---|
1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#include <nxt_router.h> 8#include <nxt_http.h> 9 10 11/* 12 * nxt_h1p_conn_ prefix is used for connection handlers. 13 * nxt_h1p_request_ prefix is used for HTTP/1 protocol request methods. 14 */ 15 | 1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#include <nxt_router.h> 8#include <nxt_http.h> 9 10 11/* 12 * nxt_h1p_conn_ prefix is used for connection handlers. 13 * nxt_h1p_request_ prefix is used for HTTP/1 protocol request methods. 14 */ 15 |
16static void nxt_h1p_conn_read_header(nxt_task_t *task, void *obj, void *data); | 16static ssize_t nxt_h1p_conn_io_read_handler(nxt_conn_t *c); |
17static void nxt_h1p_conn_proto_init(nxt_task_t *task, void *obj, void *data); 18static void nxt_h1p_conn_request_init(nxt_task_t *task, void *obj, void *data); 19static void nxt_h1p_conn_header_parse(nxt_task_t *task, void *obj, void *data); 20static nxt_int_t nxt_h1p_header_process(nxt_h1proto_t *h1p, 21 nxt_http_request_t *r); 22static nxt_int_t nxt_h1p_header_buffer_test(nxt_task_t *task, 23 nxt_h1proto_t *h1p, nxt_conn_t *c, nxt_socket_conf_t *skcf); 24static nxt_int_t nxt_h1p_connection(void *ctx, nxt_http_field_t *field, --- 23 unchanged lines hidden (view full) --- 48 void *data); 49static void nxt_h1p_conn_request_send_timeout(nxt_task_t *task, void *obj, 50 void *data); 51nxt_inline void nxt_h1p_request_error(nxt_task_t *task, nxt_http_request_t *r); 52static nxt_msec_t nxt_h1p_conn_timeout_value(nxt_conn_t *c, uintptr_t data); 53 54 55static const nxt_conn_state_t nxt_h1p_idle_state; | 17static void nxt_h1p_conn_proto_init(nxt_task_t *task, void *obj, void *data); 18static void nxt_h1p_conn_request_init(nxt_task_t *task, void *obj, void *data); 19static void nxt_h1p_conn_header_parse(nxt_task_t *task, void *obj, void *data); 20static nxt_int_t nxt_h1p_header_process(nxt_h1proto_t *h1p, 21 nxt_http_request_t *r); 22static nxt_int_t nxt_h1p_header_buffer_test(nxt_task_t *task, 23 nxt_h1proto_t *h1p, nxt_conn_t *c, nxt_socket_conf_t *skcf); 24static nxt_int_t nxt_h1p_connection(void *ctx, nxt_http_field_t *field, --- 23 unchanged lines hidden (view full) --- 48 void *data); 49static void nxt_h1p_conn_request_send_timeout(nxt_task_t *task, void *obj, 50 void *data); 51nxt_inline void nxt_h1p_request_error(nxt_task_t *task, nxt_http_request_t *r); 52static nxt_msec_t nxt_h1p_conn_timeout_value(nxt_conn_t *c, uintptr_t data); 53 54 55static const nxt_conn_state_t nxt_h1p_idle_state; |
56static const nxt_conn_state_t nxt_h1p_proto_init_state; | |
57static const nxt_conn_state_t nxt_h1p_header_parse_state; 58static const nxt_conn_state_t nxt_h1p_read_body_state; 59static const nxt_conn_state_t nxt_h1p_send_state; 60static const nxt_conn_state_t nxt_h1p_keepalive_state; 61 62 63const nxt_http_proto_body_read_t nxt_http_proto_body_read[3] = { 64 nxt_h1p_request_body_read, --- 81 unchanged lines hidden (view full) --- 146 c->socket.data = NULL; 147 148 engine = task->thread->engine; 149 c->read_work_queue = &engine->fast_work_queue; 150 c->write_work_queue = &engine->fast_work_queue; 151 152 c->read_state = &nxt_h1p_idle_state; 153 | 56static const nxt_conn_state_t nxt_h1p_header_parse_state; 57static const nxt_conn_state_t nxt_h1p_read_body_state; 58static const nxt_conn_state_t nxt_h1p_send_state; 59static const nxt_conn_state_t nxt_h1p_keepalive_state; 60 61 62const nxt_http_proto_body_read_t nxt_http_proto_body_read[3] = { 63 nxt_h1p_request_body_read, --- 81 unchanged lines hidden (view full) --- 145 c->socket.data = NULL; 146 147 engine = task->thread->engine; 148 c->read_work_queue = &engine->fast_work_queue; 149 c->write_work_queue = &engine->fast_work_queue; 150 151 c->read_state = &nxt_h1p_idle_state; 152 |
154 nxt_conn_wait(c); | 153 nxt_conn_read(task->thread->engine, c); |
155} 156 157 158static const nxt_conn_state_t nxt_h1p_idle_state 159 nxt_aligned(64) = 160{ | 154} 155 156 157static const nxt_conn_state_t nxt_h1p_idle_state 158 nxt_aligned(64) = 159{ |
161 .ready_handler = nxt_h1p_conn_read_header, | 160 .ready_handler = nxt_h1p_conn_proto_init, |
162 .close_handler = nxt_h1p_conn_error, 163 .error_handler = nxt_h1p_conn_error, 164 | 161 .close_handler = nxt_h1p_conn_error, 162 .error_handler = nxt_h1p_conn_error, 163 |
164 .io_read_handler = nxt_h1p_conn_io_read_handler, 165 |
|
165 .timer_handler = nxt_h1p_conn_timeout, 166 .timer_value = nxt_h1p_conn_timeout_value, | 166 .timer_handler = nxt_h1p_conn_timeout, 167 .timer_value = nxt_h1p_conn_timeout_value, |
167 .timer_data = offsetof(nxt_socket_conf_t, idle_timeout), | 168 .timer_data = offsetof(nxt_socket_conf_t, header_read_timeout), |
168}; 169 170 | 169}; 170 171 |
171static void 172nxt_h1p_conn_read_header(nxt_task_t *task, void *obj, void *data) | 172static ssize_t 173nxt_h1p_conn_io_read_handler(nxt_conn_t *c) |
173{ 174 size_t size; | 174{ 175 size_t size; |
175 nxt_conn_t *c; | 176 ssize_t n; 177 nxt_buf_t *b; |
176 nxt_socket_conf_joint_t *joint; 177 | 178 nxt_socket_conf_joint_t *joint; 179 |
178 c = obj; 179 180 nxt_debug(task, "h1p conn read header"); 181 | |
182 joint = c->joint; 183 size = joint->socket_conf->header_buffer_size; 184 | 180 joint = c->joint; 181 size = joint->socket_conf->header_buffer_size; 182 |
185 c->read = nxt_buf_mem_alloc(c->mem_pool, size, 0); 186 if (nxt_slow_path(c->read == NULL)) { 187 nxt_h1p_conn_error(task, c, c->socket.data); 188 return; | 183 b = nxt_buf_mem_alloc(c->mem_pool, size, 0); 184 if (nxt_slow_path(b == NULL)) { 185 c->socket.error = NXT_ENOMEM; 186 return NXT_ERROR; |
189 } 190 | 187 } 188 |
191 c->read_state = &nxt_h1p_proto_init_state; | 189 n = c->io->recvbuf(c, b); |
192 | 190 |
193 nxt_conn_read(task->thread->engine, c); 194} | 191 if (n > 0) { 192 c->read = b; |
195 | 193 |
194 } else { 195 nxt_mp_free(c->mem_pool, b); 196 } |
|
196 | 197 |
197static const nxt_conn_state_t nxt_h1p_proto_init_state 198 nxt_aligned(64) = 199{ 200 .ready_handler = nxt_h1p_conn_proto_init, 201 .close_handler = nxt_h1p_conn_error, 202 .error_handler = nxt_h1p_conn_error, | 198 return n; 199} |
203 | 200 |
204 .timer_handler = nxt_h1p_conn_timeout, 205 .timer_value = nxt_h1p_conn_timeout_value, 206 .timer_data = offsetof(nxt_socket_conf_t, header_read_timeout), 207}; | |
208 | 201 |
209 | |
210static void 211nxt_h1p_conn_proto_init(nxt_task_t *task, void *obj, void *data) 212{ 213 nxt_conn_t *c; 214 nxt_h1proto_t *h1p; 215 216 c = obj; 217 --- 798 unchanged lines hidden (view full) --- 1016 next = b->next; 1017 nxt_mp_free(c->mem_pool, b); 1018 b = next; 1019 } 1020 1021 size = nxt_buf_mem_used_size(&in->mem); 1022 1023 if (size == 0) { | 202static void 203nxt_h1p_conn_proto_init(nxt_task_t *task, void *obj, void *data) 204{ 205 nxt_conn_t *c; 206 nxt_h1proto_t *h1p; 207 208 c = obj; 209 --- 798 unchanged lines hidden (view full) --- 1008 next = b->next; 1009 nxt_mp_free(c->mem_pool, b); 1010 b = next; 1011 } 1012 1013 size = nxt_buf_mem_used_size(&in->mem); 1014 1015 if (size == 0) { |
1024 in->mem.pos = in->mem.start; 1025 in->mem.free = in->mem.start; | 1016 nxt_mp_free(c->mem_pool, in); |
1026 | 1017 |
1018 c->read = NULL; |
|
1027 c->read_state = &nxt_h1p_keepalive_state; 1028 1029 nxt_conn_read(task->thread->engine, c); 1030 1031 } else { 1032 nxt_debug(task, "h1p pipelining"); 1033 1034 nxt_memmove(in->mem.start, in->mem.pos, size); --- 8 unchanged lines hidden (view full) --- 1043 1044static const nxt_conn_state_t nxt_h1p_keepalive_state 1045 nxt_aligned(64) = 1046{ 1047 .ready_handler = nxt_h1p_conn_request_init, 1048 .close_handler = nxt_h1p_conn_error, 1049 .error_handler = nxt_h1p_conn_error, 1050 | 1019 c->read_state = &nxt_h1p_keepalive_state; 1020 1021 nxt_conn_read(task->thread->engine, c); 1022 1023 } else { 1024 nxt_debug(task, "h1p pipelining"); 1025 1026 nxt_memmove(in->mem.start, in->mem.pos, size); --- 8 unchanged lines hidden (view full) --- 1035 1036static const nxt_conn_state_t nxt_h1p_keepalive_state 1037 nxt_aligned(64) = 1038{ 1039 .ready_handler = nxt_h1p_conn_request_init, 1040 .close_handler = nxt_h1p_conn_error, 1041 .error_handler = nxt_h1p_conn_error, 1042 |
1043 .io_read_handler = nxt_h1p_conn_io_read_handler, 1044 |
|
1051 .timer_handler = nxt_h1p_conn_timeout, 1052 .timer_value = nxt_h1p_conn_timeout_value, 1053 .timer_data = offsetof(nxt_socket_conf_t, idle_timeout), 1054}; 1055 1056 1057static void 1058nxt_h1p_conn_error(nxt_task_t *task, void *obj, void *data) --- 128 unchanged lines hidden --- | 1045 .timer_handler = nxt_h1p_conn_timeout, 1046 .timer_value = nxt_h1p_conn_timeout_value, 1047 .timer_data = offsetof(nxt_socket_conf_t, idle_timeout), 1048}; 1049 1050 1051static void 1052nxt_h1p_conn_error(nxt_task_t *task, void *obj, void *data) --- 128 unchanged lines hidden --- |