diff options
Diffstat (limited to '')
-rw-r--r-- | src/nxt_http_request.c | 126 |
1 files changed, 31 insertions, 95 deletions
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c index 724b0808..1265c186 100644 --- a/src/nxt_http_request.c +++ b/src/nxt_http_request.c @@ -11,6 +11,8 @@ static nxt_int_t nxt_http_validate_host(nxt_str_t *host, nxt_mp_t *mp); static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data); static void nxt_http_request_pass(nxt_task_t *task, void *obj, void *data); +static void nxt_http_request_proto_info(nxt_task_t *task, + nxt_http_request_t *r); static void nxt_http_request_mem_buf_completion(nxt_task_t *task, void *obj, void *data); static void nxt_http_request_done(nxt_task_t *task, void *obj, void *data); @@ -293,26 +295,23 @@ nxt_http_request_pass(nxt_task_t *task, void *obj, void *data) pass = r->conf->socket_conf->pass; - if (nxt_slow_path(pass == NULL)) { - goto fail; - } + if (nxt_fast_path(pass != NULL)) { - for ( ;; ) { - nxt_debug(task, "http request route: %V", &pass->name); + do { + nxt_debug(task, "http request route: %V", &pass->name); - pass = pass->handler(task, r, pass); - if (pass == NULL) { - break; - } + pass = pass->handler(task, r, pass); - if (nxt_slow_path(r->pass_count++ == 255)) { - goto fail; - } - } + if (pass == NULL) { + return; + } - return; + if (pass == NXT_HTTP_PASS_ERROR) { + break; + } -fail: + } while (r->pass_count++ < 255); + } nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR); } @@ -322,117 +321,52 @@ nxt_http_pass_t * nxt_http_request_application(nxt_task_t *task, nxt_http_request_t *r, nxt_http_pass_t *pass) { - nxt_int_t ret; - nxt_event_engine_t *engine; - nxt_app_parse_ctx_t *ar; + nxt_event_engine_t *engine; nxt_debug(task, "http request application"); - ar = nxt_mp_zget(r->mem_pool, sizeof(nxt_app_parse_ctx_t)); - if (nxt_slow_path(ar == NULL)) { - nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR); - return NULL; - } - - ar->request = r; - ar->mem_pool = r->mem_pool; nxt_mp_retain(r->mem_pool); - // STUB engine = task->thread->engine; - ar->timer.task = &engine->task; - ar->timer.work_queue = &engine->fast_work_queue; - ar->timer.log = engine->task.log; - ar->timer.bias = NXT_TIMER_DEFAULT_BIAS; - - ar->r.remote.start = nxt_sockaddr_address(r->remote); - ar->r.remote.length = r->remote->address_length; + r->timer.task = &engine->task; + r->timer.work_queue = &engine->fast_work_queue; + r->timer.log = engine->task.log; + r->timer.bias = NXT_TIMER_DEFAULT_BIAS; /* * TODO: need an application flag to get local address * required by "SERVER_ADDR" in Pyhton and PHP. Not used in Go. */ - nxt_http_request_local_addr(task, r); - - if (nxt_fast_path(r->local != NULL)) { - ar->r.local.start = nxt_sockaddr_address(r->local); - ar->r.local.length = r->local->address_length; - } - - ar->r.header.fields = r->fields; - ar->r.header.done = 1; - ar->r.header.version = r->version; - - if (r->method != NULL) { - ar->r.header.method = *r->method; - } + nxt_http_request_proto_info(task, r); if (r->host.length != 0) { - ar->r.header.server_name = r->host; + r->server_name = r->host; } else { - nxt_str_set(&ar->r.header.server_name, "localhost"); + nxt_str_set(&r->server_name, "localhost"); } - ar->r.header.target = r->target; - - if (r->path != NULL) { - ar->r.header.path = *r->path; - } - - if (r->args != NULL) { - ar->r.header.query = *r->args; - } - - if (r->content_type != NULL) { - ar->r.header.content_type.length = r->content_type->value_length; - ar->r.header.content_type.start = r->content_type->value; - } - - if (r->content_length != NULL) { - ar->r.header.content_length.length = r->content_length->value_length; - ar->r.header.content_length.start = r->content_length->value; - } - - if (r->cookie != NULL) { - ar->r.header.cookie.length = r->cookie->value_length; - ar->r.header.cookie.start = r->cookie->value; - } - - if (r->body != NULL) { - ar->r.body.buf = r->body; - ar->r.body.preread_size = r->content_length_n; - ar->r.header.parsed_content_length = r->content_length_n; - } - - ar->r.body.done = 1; - - ret = nxt_http_parse_request_init(&ar->resp_parser, r->mem_pool); - if (nxt_slow_path(ret != NXT_OK)) { - nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR); - return NULL; - } - - nxt_router_process_http_request(task, ar, pass->u.application); + nxt_router_process_http_request(task, r, pass->u.application); return NULL; } -void -nxt_http_request_read_body(nxt_task_t *task, nxt_http_request_t *r) +static void +nxt_http_request_proto_info(nxt_task_t *task, nxt_http_request_t *r) { if (r->proto.any != NULL) { - nxt_http_proto_body_read[r->protocol](task, r); + nxt_http_proto_local_addr[r->protocol](task, r); + nxt_http_proto_tls[r->protocol](task, r); } } void -nxt_http_request_local_addr(nxt_task_t *task, nxt_http_request_t *r) +nxt_http_request_read_body(nxt_task_t *task, nxt_http_request_t *r) { if (r->proto.any != NULL) { - nxt_http_proto_local_addr[r->protocol](task, r); + nxt_http_proto_body_read[r->protocol](task, r); } } @@ -589,6 +523,8 @@ nxt_http_request_error_handler(nxt_task_t *task, void *obj, void *data) nxt_debug(task, "http request error handler"); + r->error = 1; + if (proto.any != NULL) { nxt_http_proto_discard[r->protocol](task, r, nxt_http_buf_last(r)); } |