nxt_router.c (507:fa714d76592b) nxt_router.c (510:4979fe09d9cd)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_router.h>

--- 209 unchanged lines hidden (view full) ---

218static void nxt_router_app_prepare_request(nxt_task_t *task,
219 nxt_req_app_link_t *ra);
220static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
221 nxt_app_wmsg_t *wmsg);
222static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
223 nxt_app_wmsg_t *wmsg);
224static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
225 nxt_app_wmsg_t *wmsg);
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_router.h>

--- 209 unchanged lines hidden (view full) ---

218static void nxt_router_app_prepare_request(nxt_task_t *task,
219 nxt_req_app_link_t *ra);
220static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
221 nxt_app_wmsg_t *wmsg);
222static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
223 nxt_app_wmsg_t *wmsg);
224static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
225 nxt_app_wmsg_t *wmsg);
226static nxt_int_t nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
227 nxt_app_wmsg_t *wmsg);
228
226static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data);
227static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data);
228static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj,
229 void *data);
230static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj,
231 void *data);
232static void nxt_router_app_release_handler(nxt_task_t *task, void *obj,
233 void *data);
234
235static const nxt_http_request_state_t nxt_http_request_send_state;
236static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data);
237
238static nxt_router_t *nxt_router;
239
240
241static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = {
242 nxt_python_prepare_msg,
243 nxt_php_prepare_msg,
244 nxt_go_prepare_msg,
229static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data);
230static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data);
231static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj,
232 void *data);
233static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj,
234 void *data);
235static void nxt_router_app_release_handler(nxt_task_t *task, void *obj,
236 void *data);
237
238static const nxt_http_request_state_t nxt_http_request_send_state;
239static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data);
240
241static nxt_router_t *nxt_router;
242
243
244static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = {
245 nxt_python_prepare_msg,
246 nxt_php_prepare_msg,
247 nxt_go_prepare_msg,
248 nxt_perl_prepare_msg,
245};
246
247
248nxt_int_t
249nxt_router_start(nxt_task_t *task, void *data)
250{
251 nxt_int_t ret;
252 nxt_router_t *router;

--- 3533 unchanged lines hidden (view full) ---

3786
3787 } nxt_list_loop;
3788
3789 /* end-of-headers mark */
3790 NXT_WRITE(&eof);
3791
3792 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
3793
249};
250
251
252nxt_int_t
253nxt_router_start(nxt_task_t *task, void *data)
254{
255 nxt_int_t ret;
256 nxt_router_t *router;

--- 3533 unchanged lines hidden (view full) ---

3790
3791 } nxt_list_loop;
3792
3793 /* end-of-headers mark */
3794 NXT_WRITE(&eof);
3795
3796 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
3797
3794 for(b = r->body.buf; b != NULL; b = b->next) {
3798 for (b = r->body.buf; b != NULL; b = b->next) {
3795 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3796 nxt_buf_mem_used_size(&b->mem)));
3797 }
3798
3799#undef NXT_WRITE
3800#undef RC
3801
3802 return NXT_OK;

--- 69 unchanged lines hidden (view full) ---

3872
3873 method_is_post = h->method.length == 4
3874 && h->method.start[0] == 'P'
3875 && h->method.start[1] == 'O'
3876 && h->method.start[2] == 'S'
3877 && h->method.start[3] == 'T';
3878
3879 if (method_is_post) {
3799 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3800 nxt_buf_mem_used_size(&b->mem)));
3801 }
3802
3803#undef NXT_WRITE
3804#undef RC
3805
3806 return NXT_OK;

--- 69 unchanged lines hidden (view full) ---

3876
3877 method_is_post = h->method.length == 4
3878 && h->method.start[0] == 'P'
3879 && h->method.start[1] == 'O'
3880 && h->method.start[2] == 'S'
3881 && h->method.start[3] == 'T';
3882
3883 if (method_is_post) {
3880 for(b = r->body.buf; b != NULL; b = b->next) {
3884 for (b = r->body.buf; b != NULL; b = b->next) {
3881 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3882 nxt_buf_mem_used_size(&b->mem)));
3883 }
3884 }
3885
3886 nxt_list_each(field, h->fields) {
3887 RC(nxt_app_msg_write_prefixed_upcase(task, wmsg, &prefix, field->name,
3888 field->name_length));
3889 RC(nxt_app_msg_write(task, wmsg, field->value, field->value_length));
3890
3891 } nxt_list_loop;
3892
3893 /* end-of-headers mark */
3894 NXT_WRITE(&eof);
3895
3896 if (!method_is_post) {
3885 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3886 nxt_buf_mem_used_size(&b->mem)));
3887 }
3888 }
3889
3890 nxt_list_each(field, h->fields) {
3891 RC(nxt_app_msg_write_prefixed_upcase(task, wmsg, &prefix, field->name,
3892 field->name_length));
3893 RC(nxt_app_msg_write(task, wmsg, field->value, field->value_length));
3894
3895 } nxt_list_loop;
3896
3897 /* end-of-headers mark */
3898 NXT_WRITE(&eof);
3899
3900 if (!method_is_post) {
3897 for(b = r->body.buf; b != NULL; b = b->next) {
3901 for (b = r->body.buf; b != NULL; b = b->next) {
3898 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3899 nxt_buf_mem_used_size(&b->mem)));
3900 }
3901 }
3902
3903#undef NXT_WRITE
3904#undef RC
3905

--- 63 unchanged lines hidden (view full) ---

3969
3970 } nxt_list_loop;
3971
3972 /* end-of-headers mark */
3973 NXT_WRITE(&eof);
3974
3975 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
3976
3902 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3903 nxt_buf_mem_used_size(&b->mem)));
3904 }
3905 }
3906
3907#undef NXT_WRITE
3908#undef RC
3909

--- 63 unchanged lines hidden (view full) ---

3973
3974 } nxt_list_loop;
3975
3976 /* end-of-headers mark */
3977 NXT_WRITE(&eof);
3978
3979 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
3980
3977 for(b = r->body.buf; b != NULL; b = b->next) {
3981 for (b = r->body.buf; b != NULL; b = b->next) {
3978 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3979 nxt_buf_mem_used_size(&b->mem)));
3980 }
3981
3982#undef NXT_WRITE
3983#undef RC
3984
3985 return NXT_OK;
3986
3987fail:
3988
3989 return NXT_ERROR;
3990}
3991
3992
3982 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
3983 nxt_buf_mem_used_size(&b->mem)));
3984 }
3985
3986#undef NXT_WRITE
3987#undef RC
3988
3989 return NXT_OK;
3990
3991fail:
3992
3993 return NXT_ERROR;
3994}
3995
3996
3997static nxt_int_t
3998nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
3999 nxt_app_wmsg_t *wmsg)
4000{
4001 nxt_int_t rc;
4002 nxt_str_t str;
4003 nxt_buf_t *b;
4004 nxt_http_field_t *field;
4005 nxt_app_request_header_t *h;
4006
4007 static const nxt_str_t prefix = nxt_string("HTTP_");
4008 static const nxt_str_t eof = nxt_null_string;
4009
4010 h = &r->header;
4011
4012#define RC(S) \
4013 do { \
4014 rc = (S); \
4015 if (nxt_slow_path(rc != NXT_OK)) { \
4016 goto fail; \
4017 } \
4018 } while(0)
4019
4020#define NXT_WRITE(N) \
4021 RC(nxt_app_msg_write_str(task, wmsg, N))
4022
4023 /* TODO error handle, async mmap buffer assignment */
4024
4025 NXT_WRITE(&h->method);
4026 NXT_WRITE(&h->target);
4027
4028 if (h->query.length) {
4029 str.start = h->target.start;
4030 str.length = (h->target.length - h->query.length) - 1;
4031
4032 RC(nxt_app_msg_write_str(task, wmsg, &str));
4033
4034 } else {
4035 NXT_WRITE(&eof);
4036 }
4037
4038 if (h->query.start != NULL) {
4039 RC(nxt_app_msg_write_size(task, wmsg,
4040 h->query.start - h->target.start + 1));
4041 } else {
4042 RC(nxt_app_msg_write_size(task, wmsg, 0));
4043 }
4044
4045 NXT_WRITE(&h->version);
4046
4047 NXT_WRITE(&r->remote);
4048 NXT_WRITE(&r->local);
4049
4050 NXT_WRITE(&h->host);
4051 NXT_WRITE(&h->content_type);
4052 NXT_WRITE(&h->content_length);
4053
4054 nxt_list_each(field, h->fields) {
4055 RC(nxt_app_msg_write_prefixed_upcase(task, wmsg, &prefix,
4056 field->name, field->name_length));
4057 RC(nxt_app_msg_write(task, wmsg, field->value, field->value_length));
4058 } nxt_list_loop;
4059
4060 /* end-of-headers mark */
4061 NXT_WRITE(&eof);
4062
4063 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
4064
4065 for (b = r->body.buf; b != NULL; b = b->next) {
4066
4067 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
4068 nxt_buf_mem_used_size(&b->mem)));
4069 }
4070
4071#undef NXT_WRITE
4072#undef RC
4073
4074 return NXT_OK;
4075
4076fail:
4077
4078 return NXT_ERROR;
4079}
4080
4081
3993const nxt_conn_state_t nxt_router_conn_close_state
3994 nxt_aligned(64) =
3995{
3996 .ready_handler = nxt_router_conn_free,
3997};
3998
3999
4000static void

--- 52 unchanged lines hidden ---
4082const nxt_conn_state_t nxt_router_conn_close_state
4083 nxt_aligned(64) =
4084{
4085 .ready_handler = nxt_router_conn_free,
4086};
4087
4088
4089static void

--- 52 unchanged lines hidden ---