2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) Unbit S.a.s. 2009-2010
|
2010-06-02 00:10:05 +08:00
|
|
|
* Copyright (C) 2008 Manlio Perillo (manlio.perillo@gmail.com)
|
|
|
|
* Copyright (C) Igor Sysoev
|
2010-06-01 23:53:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
#include <ngx_http.h>
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ngx_http_upstream_conf_t upstream;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_array_t *flushes;
|
|
|
|
ngx_array_t *params_len;
|
|
|
|
ngx_array_t *params;
|
|
|
|
ngx_array_t *params_source;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_array_t *uwsgi_lengths;
|
|
|
|
ngx_array_t *uwsgi_values;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:46:01 +08:00
|
|
|
ngx_str_t uwsgi_string;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 04:19:57 +08:00
|
|
|
ngx_uint_t modifier1;
|
|
|
|
ngx_uint_t modifier2;
|
2010-06-01 23:53:11 +08:00
|
|
|
} ngx_http_uwsgi_loc_conf_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_uint_t status;
|
|
|
|
ngx_uint_t status_count;
|
|
|
|
u_char *status_start;
|
|
|
|
u_char *status_end;
|
2010-06-01 23:53:11 +08:00
|
|
|
} ngx_http_uwsgi_ctx_t;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
|
|
|
|
#define NGX_HTTP_UWSGI_PARSE_NO_HEADER 20
|
|
|
|
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
static ngx_int_t ngx_http_uwsgi_eval(ngx_http_request_t *r,
|
|
|
|
ngx_http_uwsgi_loc_conf_t *uwcf);
|
|
|
|
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);
|
|
|
|
static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r,
|
|
|
|
ngx_int_t rc);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
static ngx_int_t ngx_http_uwsgi_add_variables(ngx_conf_t *cf);
|
|
|
|
static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
|
|
|
|
static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
|
|
|
|
void *child);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
|
|
void *conf);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 04:19:57 +08:00
|
|
|
static ngx_conf_num_bounds_t ngx_http_uwsgi_modifier_bounds = {
|
|
|
|
ngx_conf_check_num_bounds, 0, 255
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-01 23:53:11 +08:00
|
|
|
static ngx_conf_bitmask_t ngx_http_uwsgi_next_upstream_masks[] = {
|
2010-06-02 00:00:42 +08:00
|
|
|
{ ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
|
|
|
|
{ ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
|
|
|
|
{ ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
|
|
|
|
{ ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
|
|
|
|
{ ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
|
|
|
|
{ ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
|
|
|
|
{ ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
|
|
|
|
{ ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
|
|
|
|
{ ngx_null_string, 0 }
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_conf_bitmask_t ngx_http_uwsgi_ignore_headers_masks[] = {
|
2010-06-02 00:00:42 +08:00
|
|
|
{ ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT },
|
|
|
|
{ ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES },
|
|
|
|
{ ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES },
|
|
|
|
{ ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL },
|
|
|
|
{ ngx_null_string, 0 }
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ngx_module_t ngx_http_uwsgi_module;
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_command_t ngx_http_uwsgi_commands[] = {
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
{ ngx_string("uwsgi_pass"),
|
|
|
|
NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_http_uwsgi_pass,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
0,
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_modifier1"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
2010-06-02 04:19:57 +08:00
|
|
|
ngx_conf_set_num_slot,
|
2010-06-02 00:00:42 +08:00
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
2010-06-02 04:19:57 +08:00
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, modifier1),
|
|
|
|
&ngx_http_uwsgi_modifier_bounds },
|
2010-06-02 00:00:42 +08:00
|
|
|
|
|
|
|
{ ngx_string("uwsgi_modifier2"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
2010-06-02 04:19:57 +08:00
|
|
|
ngx_conf_set_num_slot,
|
2010-06-02 00:00:42 +08:00
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
2010-06-02 04:19:57 +08:00
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, modifier2),
|
|
|
|
&ngx_http_uwsgi_modifier_bounds },
|
2010-06-02 00:00:42 +08:00
|
|
|
|
|
|
|
{ ngx_string("uwsgi_ignore_client_abort"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_flag_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.ignore_client_abort),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_connect_timeout"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_msec_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.connect_timeout),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_send_timeout"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_msec_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.send_timeout),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_buffer_size"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_size_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.buffer_size),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_pass_request_headers"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_flag_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_request_headers),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_pass_request_body"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_flag_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_request_body),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_intercept_errors"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_flag_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.intercept_errors),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_read_timeout"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_msec_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.read_timeout),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_buffers"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
|
|
ngx_conf_set_bufs_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.bufs),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_busy_buffers_size"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_size_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.busy_buffers_size_conf),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_temp_path"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
|
|
ngx_conf_set_path_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.temp_path),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_max_temp_file_size"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_size_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.max_temp_file_size_conf),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_temp_file_write_size"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_size_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.temp_file_write_size_conf),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_next_upstream"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
|
|
ngx_conf_set_bitmask_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.next_upstream),
|
|
|
|
&ngx_http_uwsgi_next_upstream_masks },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_param"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
|
|
ngx_conf_set_keyval_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, params_source),
|
|
|
|
NULL },
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
{ ngx_string("uwsgi_string"),
|
2010-06-02 00:00:42 +08:00
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
2010-06-01 23:53:11 +08:00
|
|
|
ngx_conf_set_str_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, uwsgi_string),
|
|
|
|
NULL },
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
{ ngx_string("uwsgi_pass_header"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_str_array_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_headers),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_hide_header"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
|
|
ngx_conf_set_str_array_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.hide_headers),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("uwsgi_ignore_headers"),
|
|
|
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
|
|
ngx_conf_set_bitmask_slot,
|
|
|
|
NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
|
offsetof(ngx_http_uwsgi_loc_conf_t, upstream.ignore_headers),
|
|
|
|
&ngx_http_uwsgi_ignore_headers_masks },
|
|
|
|
|
|
|
|
ngx_null_command
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_http_module_t ngx_http_uwsgi_module_ctx = {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_add_variables, /* preconfiguration */
|
|
|
|
NULL, /* postconfiguration */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
NULL, /* create main configuration */
|
|
|
|
NULL, /* init main configuration */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
NULL, /* create server configuration */
|
|
|
|
NULL, /* merge server configuration */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
ngx_http_uwsgi_create_loc_conf, /* create location configuration */
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_merge_loc_conf /* merge location configuration */
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ngx_module_t ngx_http_uwsgi_module = {
|
|
|
|
NGX_MODULE_V1,
|
2010-06-02 00:00:42 +08:00
|
|
|
&ngx_http_uwsgi_module_ctx, /* module context */
|
|
|
|
ngx_http_uwsgi_commands, /* module directives */
|
|
|
|
NGX_HTTP_MODULE, /* module type */
|
|
|
|
NULL, /* init master */
|
|
|
|
NULL, /* init module */
|
|
|
|
NULL, /* init process */
|
|
|
|
NULL, /* init thread */
|
|
|
|
NULL, /* exit thread */
|
|
|
|
NULL, /* exit process */
|
|
|
|
NULL, /* exit master */
|
2010-06-01 23:53:11 +08:00
|
|
|
NGX_MODULE_V1_PADDING
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_http_variable_t ngx_http_uwsgi_vars[] = {
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_str_t ngx_http_uwsgi_hide_headers[] = {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_string("Status"),
|
|
|
|
ngx_string("X-Accel-Expires"),
|
|
|
|
ngx_string("X-Accel-Redirect"),
|
|
|
|
ngx_string("X-Accel-Limit-Rate"),
|
|
|
|
ngx_string("X-Accel-Buffering"),
|
|
|
|
ngx_string("X-Accel-Charset"),
|
2010-06-01 23:53:11 +08:00
|
|
|
ngx_null_string
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_path_init_t ngx_http_uwsgi_temp_path = {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_string(NGX_HTTP_UWSGI_TEMP_PATH), { 1, 2, 0 }
|
2010-06-01 23:53:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_handler(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_int_t rc;
|
|
|
|
ngx_http_upstream_t *u;
|
|
|
|
ngx_http_uwsgi_ctx_t *ctx;
|
|
|
|
ngx_http_uwsgi_loc_conf_t *uwcf;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (r->subrequest_in_memory) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
|
|
"ngx_http_uwsgi_module does not support "
|
|
|
|
"subrequests in memory");
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_http_upstream_create(r) != NGX_OK) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uwsgi_ctx_t));
|
|
|
|
if (ctx == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_set_ctx(r, ctx, ngx_http_uwsgi_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (uwcf->uwsgi_lengths) {
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_http_uwsgi_eval(r, uwcf) != NGX_OK) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u = r->upstream;
|
|
|
|
|
2010-06-02 00:12:00 +08:00
|
|
|
ngx_str_set(&u->schema, "uwsgi://");
|
2010-06-02 00:00:42 +08:00
|
|
|
u->output.tag = (ngx_buf_tag_t) &ngx_http_uwsgi_module;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
u->conf = &uwcf->upstream;
|
|
|
|
|
|
|
|
u->create_request = ngx_http_uwsgi_create_request;
|
|
|
|
u->reinit_request = ngx_http_uwsgi_reinit_request;
|
|
|
|
u->process_header = ngx_http_uwsgi_process_status_line;
|
|
|
|
u->abort_request = ngx_http_uwsgi_abort_request;
|
|
|
|
u->finalize_request = ngx_http_uwsgi_finalize_request;
|
|
|
|
|
|
|
|
u->buffering = 1;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
if (u->pipe == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u->pipe->input_filter = ngx_event_pipe_copy_input_filter;
|
|
|
|
u->pipe->input_ctx = r;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return rc;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_url_t u;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memzero(&u, sizeof(ngx_url_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_http_script_run(r, &u.url, uwcf->uwsgi_lengths->elts, 0,
|
|
|
|
uwcf->uwsgi_values->elts)
|
|
|
|
== NULL)
|
|
|
|
{
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u.no_resolve = 1;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_parse_url(r->pool, &u) != NGX_OK) {
|
2010-06-01 23:55:04 +08:00
|
|
|
if (u.err) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
|
|
"%s in upstream \"%V\"", u.err, &u.url);
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (u.no_port) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
|
|
"no port in upstream \"%V\"", &u.url);
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
r->upstream->resolved = ngx_pcalloc(r->pool,
|
|
|
|
sizeof(ngx_http_upstream_resolved_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
if (r->upstream->resolved == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (u.addrs && u.addrs[0].sockaddr) {
|
2010-06-01 23:55:04 +08:00
|
|
|
r->upstream->resolved->sockaddr = u.addrs[0].sockaddr;
|
|
|
|
r->upstream->resolved->socklen = u.addrs[0].socklen;
|
|
|
|
r->upstream->resolved->naddrs = 1;
|
|
|
|
r->upstream->resolved->host = u.addrs[0].name;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
2010-06-01 23:55:04 +08:00
|
|
|
r->upstream->resolved->host = u.host;
|
|
|
|
r->upstream->resolved->port = u.port;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_create_request(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 01:25:36 +08:00
|
|
|
u_char ch;
|
2010-06-02 01:04:56 +08:00
|
|
|
size_t key_len, val_len, len;
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_uint_t i, n;
|
|
|
|
ngx_buf_t *b;
|
|
|
|
ngx_chain_t *cl, *body;
|
|
|
|
ngx_list_part_t *part;
|
|
|
|
ngx_table_elt_t *header;
|
|
|
|
ngx_http_script_code_pt code;
|
|
|
|
ngx_http_script_engine_t e, le;
|
|
|
|
ngx_http_uwsgi_loc_conf_t *uwcf;
|
|
|
|
ngx_http_script_len_code_pt lcode;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
len = 0;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (uwcf->params_len) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_script_flush_no_cacheable_variables(r, uwcf->flushes);
|
2010-06-01 23:55:04 +08:00
|
|
|
le.flushed = 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
le.ip = uwcf->params_len->elts;
|
|
|
|
le.request = r;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
while (*(uintptr_t *) le.ip) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
2010-06-02 00:00:42 +08:00
|
|
|
key_len = lcode(&le);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode (&le)) {
|
|
|
|
lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
|
|
}
|
2010-06-02 00:00:42 +08:00
|
|
|
le.ip += sizeof(uintptr_t);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
len += 2 + key_len + 2 + val_len;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uwcf->upstream.pass_request_headers) {
|
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
part = &r->headers_in.headers.part;
|
|
|
|
header = part->elts;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
for (i = 0; /* void */ ; i++) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (i >= part->nelts) {
|
|
|
|
if (part->next == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
part = part->next;
|
|
|
|
header = part->elts;
|
|
|
|
i = 0;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
len += 2 + 5 + header[i].key.len + 2 + header[i].value.len;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
|
2010-06-02 01:04:56 +08:00
|
|
|
len += uwcf->uwsgi_string.len;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
#if 0
|
|
|
|
/* allow custom uwsgi packet */
|
2010-06-02 01:04:56 +08:00
|
|
|
if (len > 0 && len < 2) {
|
2010-06-01 23:55:04 +08:00
|
|
|
ngx_log_error (NGX_LOG_ALERT, r->connection->log, 0,
|
2010-06-02 01:04:56 +08:00
|
|
|
"uwsgi request is too little: %uz", len);
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
2010-06-02 00:00:42 +08:00
|
|
|
#endif
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
b = ngx_create_temp_buf(r->pool, len + 4);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (b == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
cl = ngx_alloc_chain_link(r->pool);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (cl == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cl->buf = b;
|
|
|
|
|
2010-06-02 04:19:57 +08:00
|
|
|
*b->last++ = (u_char) uwcf->modifier1;
|
2010-06-02 01:04:56 +08:00
|
|
|
*b->last++ = (u_char) (len & 0xff);
|
|
|
|
*b->last++ = (u_char) ((len >> 8) & 0xff);
|
2010-06-02 04:19:57 +08:00
|
|
|
*b->last++ = (u_char) uwcf->modifier2;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (uwcf->params_len) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
e.ip = uwcf->params->elts;
|
|
|
|
e.pos = b->last;
|
|
|
|
e.request = r;
|
|
|
|
e.flushed = 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
le.ip = uwcf->params_len->elts;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
while (*(uintptr_t *) le.ip) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
|
|
key_len = (u_char) lcode (&le);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
2010-06-01 23:55:04 +08:00
|
|
|
lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
|
|
}
|
2010-06-02 00:00:42 +08:00
|
|
|
le.ip += sizeof(uintptr_t);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
*e.pos++ = (u_char) (key_len & 0xff);
|
|
|
|
*e.pos++ = (u_char) ((key_len >> 8) & 0xff);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:25:36 +08:00
|
|
|
code = *(ngx_http_script_code_pt *) e.ip;
|
|
|
|
code((ngx_http_script_engine_t *) & e);
|
|
|
|
|
|
|
|
*e.pos++ = (u_char) (val_len & 0xff);
|
|
|
|
*e.pos++ = (u_char) ((val_len >> 8) & 0xff);
|
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
while (*(uintptr_t *) e.ip) {
|
|
|
|
code = *(ngx_http_script_code_pt *) e.ip;
|
2010-06-02 00:00:42 +08:00
|
|
|
code((ngx_http_script_engine_t *) & e);
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
e.ip += sizeof(uintptr_t);
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
b->last = e.pos;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uwcf->upstream.pass_request_headers) {
|
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
part = &r->headers_in.headers.part;
|
|
|
|
header = part->elts;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
for (i = 0; /* void */ ; i++) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (i >= part->nelts) {
|
|
|
|
if (part->next == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
part = part->next;
|
|
|
|
header = part->elts;
|
|
|
|
i = 0;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:04:56 +08:00
|
|
|
key_len = 5 + header[i].key.len;
|
|
|
|
*b->last++ = (u_char) (key_len & 0xff);
|
|
|
|
*b->last++ = (u_char) ((key_len >> 8) & 0xff);
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
b->last = ngx_cpymem(b->last, "HTTP_", 5);
|
2010-06-01 23:55:04 +08:00
|
|
|
for (n = 0; n < header[i].key.len; n++) {
|
|
|
|
ch = header[i].key.data[n];
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (ch >= 'a' && ch <= 'z') {
|
|
|
|
ch &= ~0x20;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
} else if (ch == '-') {
|
2010-06-01 23:55:04 +08:00
|
|
|
ch = '_';
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
*b->last++ = ch;
|
|
|
|
}
|
2010-06-02 01:04:56 +08:00
|
|
|
|
|
|
|
val_len = header[i].value.len;
|
|
|
|
*b->last++ = (u_char) (val_len & 0xff);
|
|
|
|
*b->last++ = (u_char) ((val_len >> 8) & 0xff);
|
|
|
|
b->last = ngx_copy(b->last, header[i].value.data, val_len);
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
|
2010-06-02 00:00:42 +08:00
|
|
|
b->last = ngx_copy(b->last, uwcf->uwsgi_string.data,
|
|
|
|
uwcf->uwsgi_string.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uwcf->upstream.pass_request_body) {
|
2010-06-01 23:55:04 +08:00
|
|
|
body = r->upstream->request_bufs;
|
|
|
|
r->upstream->request_bufs = cl;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
while (body) {
|
2010-06-02 00:00:42 +08:00
|
|
|
b = ngx_alloc_buf(r->pool);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (b == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
cl->next = ngx_alloc_chain_link(r->pool);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (cl->next == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
cl = cl->next;
|
|
|
|
cl->buf = b;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
body = body->next;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
b->flush = 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
2010-06-01 23:55:04 +08:00
|
|
|
r->upstream->request_bufs = cl;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cl->next = NULL;
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_reinit_request(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_ctx_t *ctx;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ctx == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_OK;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ctx->status = 0;
|
|
|
|
ctx->status_count = 0;
|
|
|
|
ctx->status_start = NULL;
|
|
|
|
ctx->status_end = NULL;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
r->upstream->process_header = ngx_http_uwsgi_process_status_line;
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_parse_status_line(ngx_http_request_t *r,
|
|
|
|
ngx_http_uwsgi_ctx_t *ctx)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
u_char ch;
|
|
|
|
u_char *p;
|
|
|
|
ngx_http_upstream_t *u;
|
2010-06-01 23:53:11 +08:00
|
|
|
enum {
|
2010-06-01 23:55:04 +08:00
|
|
|
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
|
2010-06-01 23:53:11 +08:00
|
|
|
} state;
|
|
|
|
|
|
|
|
u = r->upstream;
|
|
|
|
|
|
|
|
state = r->state;
|
|
|
|
|
|
|
|
for (p = u->buffer.pos; p < u->buffer.last; p++) {
|
2010-06-01 23:55:04 +08:00
|
|
|
ch = *p;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* "HTTP/" */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_start:
|
|
|
|
switch (ch) {
|
|
|
|
case 'H':
|
|
|
|
state = sw_H;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sw_H:
|
|
|
|
switch (ch) {
|
|
|
|
case 'T':
|
|
|
|
state = sw_HT;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sw_HT:
|
|
|
|
switch (ch) {
|
|
|
|
case 'T':
|
|
|
|
state = sw_HTT;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sw_HTT:
|
|
|
|
switch (ch) {
|
|
|
|
case 'P':
|
|
|
|
state = sw_HTTP;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sw_HTTP:
|
|
|
|
switch (ch) {
|
|
|
|
case '/':
|
|
|
|
state = sw_first_major_digit;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* the first digit of major HTTP version */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_first_major_digit:
|
|
|
|
if (ch < '1' || ch > '9') {
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
state = sw_major_digit;
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* the major HTTP version or dot */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_major_digit:
|
|
|
|
if (ch == '.') {
|
|
|
|
state = sw_first_minor_digit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch < '0' || ch > '9') {
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* the first digit of minor HTTP version */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_first_minor_digit:
|
|
|
|
if (ch < '0' || ch > '9') {
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
state = sw_minor_digit;
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* the minor HTTP version or the end of the request line */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_minor_digit:
|
|
|
|
if (ch == ' ') {
|
|
|
|
state = sw_status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch < '0' || ch > '9') {
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* HTTP status code */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_status:
|
|
|
|
if (ch == ' ') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch < '0' || ch > '9') {
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->status = ctx->status * 10 + ch - '0';
|
|
|
|
|
|
|
|
if (++ctx->status_count == 3) {
|
|
|
|
state = sw_space_after_status;
|
|
|
|
ctx->status_start = p - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* space or end of line */
|
2010-06-01 23:55:04 +08:00
|
|
|
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:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* any text until end of line */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_status_text:
|
|
|
|
switch (ch) {
|
|
|
|
case CR:
|
|
|
|
state = sw_almost_done;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case LF:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
/* end of status line */
|
2010-06-01 23:55:04 +08:00
|
|
|
case sw_almost_done:
|
|
|
|
ctx->status_end = p - 1;
|
|
|
|
switch (ch) {
|
|
|
|
case LF:
|
|
|
|
goto done;
|
|
|
|
default:
|
2010-06-02 00:00:42 +08:00
|
|
|
return NGX_HTTP_UWSGI_PARSE_NO_HEADER;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u->buffer.pos = p;
|
|
|
|
r->state = state;
|
|
|
|
|
|
|
|
return NGX_AGAIN;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
done:
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
u->buffer.pos = p + 1;
|
|
|
|
|
|
|
|
if (ctx->status_end == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
ctx->status_end = p;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
r->state = sw_start;
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_process_status_line(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_int_t rc;
|
|
|
|
ngx_http_upstream_t *u;
|
|
|
|
ngx_http_uwsgi_ctx_t *ctx;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (ctx == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
rc = ngx_http_uwsgi_parse_status_line(r, ctx);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (rc == NGX_AGAIN) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return rc;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u = r->upstream;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (rc == NGX_HTTP_UWSGI_PARSE_NO_HEADER) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
|
|
"upstream sent no valid HTTP/1.0 header");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
r->http_version = NGX_HTTP_VERSION_9;
|
|
|
|
u->headers_in.status_n = NGX_HTTP_OK;
|
|
|
|
u->state->status = NGX_HTTP_OK;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_OK;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (u->state) {
|
2010-06-01 23:55:04 +08:00
|
|
|
u->state->status = ctx->status;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u->headers_in.status_n = ctx->status;
|
|
|
|
|
|
|
|
u->headers_in.status_line.len = ctx->status_end - ctx->status_start;
|
2010-06-02 00:00:42 +08:00
|
|
|
u->headers_in.status_line.data = ngx_pnalloc(r->pool,
|
|
|
|
u->headers_in.status_line.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (u->headers_in.status_line.data == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memcpy(u->headers_in.status_line.data, ctx->status_start,
|
|
|
|
u->headers_in.status_line.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"http uwsgi status %ui \"%V\"",
|
|
|
|
u->headers_in.status_n, &u->headers_in.status_line);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
u->process_header = ngx_http_uwsgi_process_header;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
return ngx_http_uwsgi_process_header(r);
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_process_header(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_int_t rc;
|
|
|
|
ngx_table_elt_t *h;
|
|
|
|
ngx_http_upstream_header_t *hh;
|
|
|
|
ngx_http_upstream_main_conf_t *umcf;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
for ( ;; ) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (rc == NGX_OK) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
/* a header line has been parsed successfully */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
h = ngx_list_push(&r->upstream->headers_in.headers);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (h == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
h->hash = r->header_hash;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
h->key.len = r->header_name_end - r->header_name_start;
|
|
|
|
h->value.len = r->header_end - r->header_start;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
h->key.data = ngx_pnalloc(r->pool,
|
|
|
|
h->key.len + 1 + h->value.len + 1
|
|
|
|
+ h->key.len);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (h->key.data == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
h->value.data = h->key.data + h->key.len + 1;
|
|
|
|
h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);
|
|
|
|
ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (h->key.len == r->lowcase_index) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
|
|
|
ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
|
|
h->lowcase_key, h->key.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"http uwsgi header: \"%V: %V\"", &h->key, &h->value);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
continue;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
/* a whole header has been parsed successfully */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"http uwsgi header done");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
/*
|
|
|
|
* if no "Server" and "Date" in header line,
|
|
|
|
* then add the special empty headers
|
|
|
|
*/
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (r->upstream->headers_in.server == NULL) {
|
2010-06-02 00:00:42 +08:00
|
|
|
h = ngx_list_push(&r->upstream->headers_in.headers);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (h == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
|
|
|
|
ngx_hash ('s', 'e'), 'r'), 'v'), 'e'), 'r');
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:12:00 +08:00
|
|
|
ngx_str_set(&h->key, "Server");
|
|
|
|
ngx_str_null(&h->value);
|
2010-06-01 23:55:04 +08:00
|
|
|
h->lowcase_key = (u_char *) "server";
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (r->upstream->headers_in.date == NULL) {
|
2010-06-02 00:00:42 +08:00
|
|
|
h = ngx_list_push(&r->upstream->headers_in.headers);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (h == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e');
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:12:00 +08:00
|
|
|
ngx_str_set(&h->key, "Date");
|
|
|
|
ngx_str_null(&h->value);
|
2010-06-01 23:55:04 +08:00
|
|
|
h->lowcase_key = (u_char *) "date";
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (rc == NGX_AGAIN) {
|
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
/* there was error while a header line parsing */
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
|
|
"upstream sent invalid header");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_abort_request(ngx_http_request_t *r)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"abort http uwsgi request");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"finalize http uwsgi request");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_add_variables(ngx_conf_t *cf)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_variable_t *var, *v;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
for (v = ngx_http_uwsgi_vars; v->name.len; v++) {
|
2010-06-02 00:00:42 +08:00
|
|
|
var = ngx_http_add_variable(cf, &v->name, v->flags);
|
2010-06-01 23:55:04 +08:00
|
|
|
if (var == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
var->get_handler = v->get_handler;
|
|
|
|
var->data = v->data;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_loc_conf_t *conf;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
if (conf == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NULL;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 04:19:57 +08:00
|
|
|
conf->modifier1 = NGX_CONF_UNSET_UINT;
|
|
|
|
conf->modifier2 = NGX_CONF_UNSET_UINT;
|
|
|
|
|
2010-06-01 23:53:11 +08:00
|
|
|
conf->upstream.store = NGX_CONF_UNSET;
|
|
|
|
conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
|
|
|
conf->upstream.buffering = NGX_CONF_UNSET;
|
|
|
|
conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
|
|
|
|
|
|
|
conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
|
|
conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
|
|
|
conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
|
|
|
|
|
|
conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
|
|
|
conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
|
|
|
|
|
|
|
conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
|
|
|
conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
|
|
|
conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
|
|
|
|
|
|
|
conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
|
|
conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
|
|
|
|
|
|
conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
|
|
conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
|
|
|
|
|
|
conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
|
|
|
|
|
|
|
/* "uwsgi_cyclic_temp_file" is disabled */
|
|
|
|
conf->upstream.cyclic_temp_file = 0;
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
|
|
|
ngx_http_uwsgi_loc_conf_t *prev = parent;
|
|
|
|
ngx_http_uwsgi_loc_conf_t *conf = child;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
u_char *p;
|
|
|
|
size_t size;
|
|
|
|
uintptr_t *code;
|
|
|
|
ngx_uint_t i;
|
|
|
|
ngx_keyval_t *src;
|
|
|
|
ngx_hash_init_t hash;
|
|
|
|
ngx_http_script_compile_t sc;
|
|
|
|
ngx_http_script_copy_code_t *copy;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.store != 0) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
if (conf->upstream.store_lengths == NULL) {
|
|
|
|
conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
|
|
conf->upstream.store_values = prev->upstream.store_values;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
|
|
prev->upstream.store_access, 0600);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_value(conf->upstream.buffering,
|
|
|
|
prev->upstream.buffering, 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
|
|
prev->upstream.ignore_client_abort, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
|
|
prev->upstream.connect_timeout, 60000);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
|
|
prev->upstream.send_timeout, 60000);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
|
|
prev->upstream.read_timeout, 60000);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
|
|
prev->upstream.send_lowat, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
|
|
prev->upstream.buffer_size,
|
|
|
|
(size_t) ngx_pagesize);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
|
|
8, ngx_pagesize);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.bufs.num < 2) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"there must be at least 2 \"uwsgi_buffers\"");
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size = conf->upstream.buffer_size;
|
|
|
|
if (size < conf->upstream.bufs.size) {
|
2010-06-01 23:55:04 +08:00
|
|
|
size = conf->upstream.bufs.size;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
|
|
prev->upstream.busy_buffers_size_conf,
|
|
|
|
NGX_CONF_UNSET_SIZE);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.busy_buffers_size = 2 * size;
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.busy_buffers_size =
|
|
|
|
conf->upstream.busy_buffers_size_conf;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->upstream.busy_buffers_size < size) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"\"uwsgi_busy_buffers_size\" must be equal or bigger "
|
|
|
|
"than maximum of the value of \"uwsgi_buffer_size\" and "
|
|
|
|
"one of the \"uwsgi_buffers\"");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->upstream.busy_buffers_size
|
2010-06-02 00:00:42 +08:00
|
|
|
> (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
|
|
|
{
|
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"\"uwsgi_busy_buffers_size\" must be less than "
|
|
|
|
"the size of all \"uwsgi_buffers\" minus one buffer");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
|
|
prev->upstream.temp_file_write_size_conf,
|
|
|
|
NGX_CONF_UNSET_SIZE);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.temp_file_write_size = 2 * size;
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.temp_file_write_size =
|
|
|
|
conf->upstream.temp_file_write_size_conf;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->upstream.temp_file_write_size < size) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"\"uwsgi_temp_file_write_size\" must be equal or bigger than "
|
|
|
|
"maximum of the value of \"uwsgi_buffer_size\" and "
|
|
|
|
"one of the \"uwsgi_buffers\"");
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
|
|
prev->upstream.max_temp_file_size_conf,
|
|
|
|
NGX_CONF_UNSET_SIZE);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
2010-06-02 00:00:42 +08:00
|
|
|
} else {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.max_temp_file_size =
|
|
|
|
conf->upstream.max_temp_file_size_conf;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->upstream.max_temp_file_size != 0
|
2010-06-01 23:55:04 +08:00
|
|
|
&& conf->upstream.max_temp_file_size < size) {
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"\"uwsgi_max_temp_file_size\" must be equal to zero to disable "
|
|
|
|
"the temporary files usage or must be equal or bigger than "
|
|
|
|
"maximum of the value of \"uwsgi_buffer_size\" and "
|
|
|
|
"one of the \"uwsgi_buffers\"");
|
2010-06-01 23:55:04 +08:00
|
|
|
|
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
|
|
|
|
prev->upstream.ignore_headers,
|
|
|
|
NGX_CONF_BITMASK_SET);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
|
|
prev->upstream.next_upstream,
|
|
|
|
(NGX_CONF_BITMASK_SET
|
|
|
|
|NGX_HTTP_UPSTREAM_FT_ERROR
|
|
|
|
|NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
2010-06-02 00:00:42 +08:00
|
|
|
|NGX_HTTP_UPSTREAM_FT_OFF;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
|
|
|
|
prev->upstream.temp_path,
|
|
|
|
&ngx_http_uwsgi_temp_path)
|
|
|
|
!= NGX_OK)
|
|
|
|
{
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
|
|
prev->upstream.pass_request_headers, 1);
|
|
|
|
ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
|
|
prev->upstream.pass_request_body, 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
|
|
prev->upstream.intercept_errors, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
ngx_conf_merge_str_value(conf->uwsgi_string, prev->uwsgi_string, "");
|
|
|
|
|
|
|
|
hash.max_size = 512;
|
2010-06-02 00:00:42 +08:00
|
|
|
hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
2010-06-01 23:53:11 +08:00
|
|
|
hash.name = "uwsgi_hide_headers_hash";
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
|
|
|
&prev->upstream,
|
|
|
|
ngx_http_uwsgi_hide_headers, &hash)
|
|
|
|
!= NGX_OK)
|
|
|
|
{
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->upstream.upstream == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->upstream.upstream = prev->upstream.upstream;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->uwsgi_lengths == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->uwsgi_lengths = prev->uwsgi_lengths;
|
|
|
|
conf->uwsgi_values = prev->uwsgi_values;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 04:19:57 +08:00
|
|
|
ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0);
|
|
|
|
ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (conf->params_source == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
conf->flushes = prev->flushes;
|
|
|
|
conf->params_len = prev->params_len;
|
|
|
|
conf->params = prev->params;
|
|
|
|
conf->params_source = prev->params_source;
|
|
|
|
|
|
|
|
if (conf->params_source == NULL) {
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (conf->params_len == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
conf->params = ngx_array_create(cf->pool, 512, 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (conf->params == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
src = conf->params_source->elts;
|
|
|
|
for (i = 0; i < conf->params_source->nelts; i++) {
|
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
copy = ngx_array_push_n(conf->params_len,
|
|
|
|
sizeof(ngx_http_script_copy_code_t));
|
|
|
|
if (copy == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
|
|
copy->len = src[i].key.len;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
size = (sizeof(ngx_http_script_copy_code_t)
|
|
|
|
+ src[i].key.len + sizeof(uintptr_t) - 1)
|
|
|
|
& ~(sizeof(uintptr_t) - 1);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
copy = ngx_array_push_n(conf->params, size);
|
|
|
|
if (copy == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
copy->code = ngx_http_script_copy_code;
|
|
|
|
copy->len = src[i].key.len;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
|
|
ngx_memcpy(p, src[i].key.data, src[i].key.len);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
sc.cf = cf;
|
|
|
|
sc.source = &src[i].value;
|
|
|
|
sc.flushes = &conf->flushes;
|
|
|
|
sc.lengths = &conf->params_len;
|
|
|
|
sc.values = &conf->params;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 01:30:23 +08:00
|
|
|
if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:55:04 +08:00
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
2010-06-01 23:55:04 +08:00
|
|
|
if (code == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
*code = (uintptr_t) NULL;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
2010-06-01 23:55:04 +08:00
|
|
|
if (code == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
*code = (uintptr_t) NULL;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
if (code == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*code = (uintptr_t) NULL;
|
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2010-06-01 23:53:11 +08:00
|
|
|
{
|
|
|
|
ngx_http_uwsgi_loc_conf_t *uwcf = conf;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_url_t u;
|
|
|
|
ngx_str_t *value, *url;
|
|
|
|
ngx_uint_t n;
|
|
|
|
ngx_http_core_loc_conf_t *clcf;
|
|
|
|
ngx_http_script_compile_t sc;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (uwcf->upstream.upstream || uwcf->uwsgi_lengths) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return "is duplicate";
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module);
|
|
|
|
clcf->handler = ngx_http_uwsgi_handler;
|
|
|
|
|
|
|
|
value = cf->args->elts;
|
|
|
|
|
|
|
|
url = &value[1];
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
n = ngx_http_script_variables_count(url);
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
if (n) {
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
sc.cf = cf;
|
|
|
|
sc.source = url;
|
|
|
|
sc.lengths = &uwcf->uwsgi_lengths;
|
|
|
|
sc.values = &uwcf->uwsgi_values;
|
|
|
|
sc.variables = n;
|
|
|
|
sc.complete_lengths = 1;
|
|
|
|
sc.complete_values = 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
if (ngx_http_script_compile(&sc) != NGX_OK) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2010-06-01 23:53:11 +08:00
|
|
|
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_OK;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
ngx_memzero(&u, sizeof(ngx_url_t));
|
2010-06-01 23:53:11 +08:00
|
|
|
|
|
|
|
u.url = value[1];
|
|
|
|
u.no_resolve = 1;
|
|
|
|
|
2010-06-02 00:00:42 +08:00
|
|
|
uwcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
2010-06-01 23:53:11 +08:00
|
|
|
if (uwcf->upstream.upstream == NULL) {
|
2010-06-01 23:55:04 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clcf->name.data[clcf->name.len - 1] == '/') {
|
2010-06-01 23:55:04 +08:00
|
|
|
clcf->auto_redirect = 1;
|
2010-06-01 23:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|