aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_uwsgi_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules/ngx_http_uwsgi_module.c')
-rw-r--r--src/http/modules/ngx_http_uwsgi_module.c232
1 files changed, 11 insertions, 221 deletions
diff --git a/src/http/modules/ngx_http_uwsgi_module.c b/src/http/modules/ngx_http_uwsgi_module.c
index 3df7c7d42..c137dbd45 100644
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -52,8 +52,6 @@ static ngx_int_t ngx_http_uwsgi_eval(ngx_http_request_t *r,
static ngx_int_t ngx_http_uwsgi_create_request(ngx_http_request_t *r);
static ngx_int_t ngx_http_uwsgi_reinit_request(ngx_http_request_t *r);
static ngx_int_t ngx_http_uwsgi_process_status_line(ngx_http_request_t *r);
-static ngx_int_t ngx_http_uwsgi_parse_status_line(ngx_http_request_t *r,
- ngx_http_uwsgi_ctx_t *ctx);
static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r);
static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r);
@@ -866,235 +864,27 @@ ngx_http_uwsgi_reinit_request(ngx_http_request_t *r)
static ngx_int_t
-ngx_http_uwsgi_parse_status_line(ngx_http_request_t *r,
- ngx_http_uwsgi_ctx_t *ctx)
-{
- u_char ch;
- u_char *p;
- ngx_http_upstream_t *u;
- enum {
- sw_start = 0,
- sw_H,
- sw_HT,
- sw_HTT,
- sw_HTTP,
- sw_first_major_digit,
- sw_major_digit,
- sw_first_minor_digit,
- sw_minor_digit,
- sw_status,
- sw_space_after_status,
- sw_status_text,
- sw_almost_done
- } state;
-
- u = r->upstream;
-
- state = r->state;
-
- for (p = u->buffer.pos; p < u->buffer.last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* "HTTP/" */
- case sw_start:
- switch (ch) {
- case 'H':
- state = sw_H;
- break;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- case sw_H:
- switch (ch) {
- case 'T':
- state = sw_HT;
- break;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- case sw_HT:
- switch (ch) {
- case 'T':
- state = sw_HTT;
- break;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- case sw_HTT:
- switch (ch) {
- case 'P':
- state = sw_HTTP;
- break;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- case sw_HTTP:
- switch (ch) {
- case '/':
- state = sw_first_major_digit;
- break;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- /* the first digit of major HTTP version */
- case sw_first_major_digit:
- if (ch < '1' || ch > '9') {
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
-
- state = sw_major_digit;
- break;
-
- /* the major HTTP version or dot */
- case sw_major_digit:
- if (ch == '.') {
- state = sw_first_minor_digit;
- break;
- }
-
- if (ch < '0' || ch > '9') {
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
-
- break;
-
- /* the first digit of minor HTTP version */
- case sw_first_minor_digit:
- if (ch < '0' || ch > '9') {
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
-
- state = sw_minor_digit;
- break;
-
- /* the minor HTTP version or the end of the request line */
- case sw_minor_digit:
- if (ch == ' ') {
- state = sw_status;
- break;
- }
-
- if (ch < '0' || ch > '9') {
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
-
- break;
-
- /* HTTP status code */
- case sw_status:
- if (ch == ' ') {
- break;
- }
-
- if (ch < '0' || ch > '9') {
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
-
- ctx->status = ctx->status * 10 + ch - '0';
-
- if (++ctx->status_count == 3) {
- state = sw_space_after_status;
- ctx->status_start = p - 2;
- }
-
- break;
-
- /* space or end of line */
- case sw_space_after_status:
- switch (ch) {
- case ' ':
- state = sw_status_text;
- break;
- case '.': /* IIS may send 403.1, 403.2, etc */
- state = sw_status_text;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- break;
-
- /* any text until end of line */
- case sw_status_text:
- switch (ch) {
- case CR:
- state = sw_almost_done;
-
- break;
- case LF:
- goto done;
- }
- break;
-
- /* end of status line */
- case sw_almost_done:
- ctx->status_end = p - 1;
- switch (ch) {
- case LF:
- goto done;
- default:
- return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
- }
- }
- }
-
- u->buffer.pos = p;
- r->state = state;
-
- return NGX_AGAIN;
-
-done:
-
- u->buffer.pos = p + 1;
-
- if (ctx->status_end == NULL) {
- ctx->status_end = p;
- }
-
- r->state = sw_start;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
ngx_http_uwsgi_process_status_line(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_upstream_t *u;
- ngx_http_uwsgi_ctx_t *ctx;
+ ngx_http_status_t *status;
- ctx = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
+ status = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
- if (ctx == NULL) {
+ if (status == NULL) {
return NGX_ERROR;
}
- rc = ngx_http_uwsgi_parse_status_line(r, ctx);
+ u = r->upstream;
+
+ rc = ngx_http_parse_status_line(r, &u->buffer, status);
if (rc == NGX_AGAIN) {
return rc;
}
- u = r->upstream;
-
- if (rc == NGX_HTTP_UWSGI_PARSE_NO_HEADER) {
+ if (rc == NGX_ERROR) {
r->http_version = NGX_HTTP_VERSION_9;
u->process_header = ngx_http_uwsgi_process_header;
@@ -1103,19 +893,19 @@ ngx_http_uwsgi_process_status_line(ngx_http_request_t *r)
}
if (u->state) {
- u->state->status = ctx->status;
+ u->state->status = status->code;
}
- u->headers_in.status_n = ctx->status;
+ u->headers_in.status_n = status->code;
- u->headers_in.status_line.len = ctx->status_end - ctx->status_start;
+ u->headers_in.status_line.len = status->end - status->start;
u->headers_in.status_line.data = ngx_pnalloc(r->pool,
u->headers_in.status_line.len);
if (u->headers_in.status_line.data == NULL) {
return NGX_ERROR;
}
- ngx_memcpy(u->headers_in.status_line.data, ctx->status_start,
+ ngx_memcpy(u->headers_in.status_line.data, status->start,
u->headers_in.status_line.len);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,