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>

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

224static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
225 nxt_app_wmsg_t *wmsg);
226static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
227 nxt_app_wmsg_t *wmsg);
228static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
229 nxt_app_wmsg_t *wmsg);
230static nxt_int_t nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
231 nxt_app_wmsg_t *wmsg);
232static nxt_int_t nxt_ruby_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
233 nxt_app_wmsg_t *wmsg);
234
235static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data);
236static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data);
237static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj,
238 void *data);
239static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj,
240 void *data);
241static void nxt_router_app_release_handler(nxt_task_t *task, void *obj,

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

247static nxt_router_t *nxt_router;
248
249
250static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = {
251 nxt_python_prepare_msg,
252 nxt_php_prepare_msg,
253 nxt_go_prepare_msg,
254 nxt_perl_prepare_msg,
255 nxt_ruby_prepare_msg,
256};
257
258
259nxt_int_t
260nxt_router_start(nxt_task_t *task, void *data)
261{
262 nxt_int_t ret;
263 nxt_router_t *router;

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

4125 return NXT_OK;
4126
4127fail:
4128
4129 return NXT_ERROR;
4130}
4131
4132
4133static nxt_int_t
4134nxt_ruby_prepare_msg(nxt_task_t *task, nxt_app_request_t *r,
4135 nxt_app_wmsg_t *wmsg)
4136{
4137 nxt_int_t rc;
4138 nxt_str_t str;
4139 nxt_buf_t *b;
4140 nxt_http_field_t *field;
4141 nxt_app_request_header_t *h;
4142
4143 static const nxt_str_t prefix = nxt_string("HTTP_");
4144 static const nxt_str_t eof = nxt_null_string;
4145
4146 h = &r->header;
4147
4148#define RC(S) \
4149 do { \
4150 rc = (S); \
4151 if (nxt_slow_path(rc != NXT_OK)) { \
4152 goto fail; \
4153 } \
4154 } while(0)
4155
4156#define NXT_WRITE(N) \
4157 RC(nxt_app_msg_write_str(task, wmsg, N))
4158
4159 /* TODO error handle, async mmap buffer assignment */
4160
4161 NXT_WRITE(&h->method);
4162 NXT_WRITE(&h->target);
4163
4164 if (h->query.length) {
4165 str.start = h->target.start;
4166 str.length = (h->target.length - h->query.length) - 1;
4167
4168 RC(nxt_app_msg_write_str(task, wmsg, &str));
4169
4170 } else {
4171 NXT_WRITE(&eof);
4172 }
4173
4174 if (h->query.start != NULL) {
4175 RC(nxt_app_msg_write_size(task, wmsg,
4176 h->query.start - h->target.start + 1));
4177 } else {
4178 RC(nxt_app_msg_write_size(task, wmsg, 0));
4179 }
4180
4181 NXT_WRITE(&h->version);
4182
4183 NXT_WRITE(&r->remote);
4184 NXT_WRITE(&r->local);
4185
4186 NXT_WRITE(&h->host);
4187 NXT_WRITE(&h->content_type);
4188 NXT_WRITE(&h->content_length);
4189
4190 nxt_list_each(field, h->fields) {
4191 RC(nxt_app_msg_write_prefixed_upcase(task, wmsg, &prefix,
4192 field->name, field->name_length));
4193 RC(nxt_app_msg_write(task, wmsg, field->value, field->value_length));
4194 } nxt_list_loop;
4195
4196 /* end-of-headers mark */
4197 NXT_WRITE(&eof);
4198
4199 RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size));
4200
4201 for (b = r->body.buf; b != NULL; b = b->next) {
4202
4203 RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos,
4204 nxt_buf_mem_used_size(&b->mem)));
4205 }
4206
4207#undef NXT_WRITE
4208#undef RC
4209
4210 return NXT_OK;
4211
4212fail:
4213
4214 return NXT_ERROR;
4215}
4216
4217
4218const nxt_conn_state_t nxt_router_conn_close_state
4219 nxt_aligned(64) =
4220{
4221 .ready_handler = nxt_router_conn_free,
4222};
4223
4224
4225static void

--- 52 unchanged lines hidden ---