ngx_hunk_tag_t tag;
ngx_output_chain_filter_pt output_filter;
- void *output_ctx;
+ void *filter_ctx;
} ngx_output_chain_ctx_t;
if (ctx->in == NULL) {
if (in == NULL) {
- return ctx->output_filter(ctx->output_ctx, in);
+ return ctx->output_filter(ctx->filter_ctx, in);
}
if (in->next == NULL
&& (!ngx_output_chain_need_to_copy(ctx, in->hunk)))
{
- return ctx->output_filter(ctx->output_ctx, in);
+ return ctx->output_filter(ctx->filter_ctx, in);
}
}
return last;
}
- last = ctx->output_filter(ctx->output_ctx, out);
+ last = ctx->output_filter(ctx->filter_ctx, out);
ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag);
last_out = &out;
}
}
+ /* ensure that there is no current pool */
+
+ ngx_pcre_pool = NULL;
+
return re;
}
static void *ngx_regex_malloc(size_t size)
{
- return ngx_palloc(ngx_pcre_pool, size);
+ if (ngx_pcre_pool) {
+ return ngx_palloc(ngx_pcre_pool, size);
+ }
+
+ return NULL;
}
bsize = 0;
to_write = 0;
+#if 0
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)) {
+#endif
for (cl = p->busy; cl; cl = cl->next) {
bsize += cl->hunk->end - cl->hunk->start;
to_write += ngx_hunk_size(cl->hunk);
}
+#if 0
}
+#endif
out = NULL;
ll = NULL;
if (p->out) {
cl = p->out;
+#if 0
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
&& (bsize + ngx_hunk_size(cl->hunk) > p->busy_size))
{
break;
}
+#else
+ if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) {
+ break;
+ }
+#endif
p->out = p->out->next;
ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks,
} else if (!p->cachable && p->in) {
cl = p->in;
+#if 0
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
&& (bsize + ngx_hunk_size(cl->hunk) > p->busy_size))
{
break;
}
+#else
+ if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) {
+ break;
+ }
+#endif
p->in = p->in->next;
void *preallocated;
char *free_mem;
- int allocated;
+ ngx_uint_t allocated;
unsigned flush:4;
unsigned redo:1;
{
ngx_http_gzip_ctx_t *ctx = opaque;
- int alloc;
- void *p;
+ void *p;
+ ngx_uint_t alloc;
alloc = items * size;
if (alloc % 512 != 0) {
ctx->allocated -= alloc;
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
- "gzip alloc: n:%d s:%d a:%d p:%08X",
+ "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT,
items, size, alloc, p);
return p;
rc = ngx_http_discard_body(r);
- if (rc != NGX_OK) {
+ if (rc != NGX_OK && rc != NGX_AGAIN) {
return rc;
}
typedef struct {
- ngx_table_t *headers; /* it must be first field */
+ ngx_table_t headers; /* it must be first field */
ngx_table_elt_t *date;
ngx_table_elt_t *server;
r = p->request;
- h = headers_in->headers->elts;
- for (i = 0; i < headers_in->headers->nelts; i++) {
+ h = headers_in->headers.elts;
+ for (i = 0; i < headers_in->headers.nelts; i++) {
if (&h[i] == headers_in->connection) {
continue;
ngx_table_elt_t *loc)
{
u_char *last;
+ ngx_table_elt_t *location;
ngx_http_request_t *r;
ngx_http_proxy_upstream_conf_t *uc;
r = p->request;
uc = p->lcf->upstream;
- r->headers_out.location = ngx_http_add_header(&r->headers_out,
- ngx_http_headers_out);
- if (r->headers_out.location == NULL) {
+ location = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
+ if (location == NULL) {
return NGX_ERROR;
}
+ /*
+ * we do not set r->headers_out.location to avoid the handling
+ * the local redirects without a host name by ngx_http_header_filter()
+ */
+
+#if 0
+ r->headers_out.location = location;
+#endif
+
if (uc->url.len > loc->value.len
|| ngx_rstrncmp(loc->value.data, uc->url.data, uc->url.len) != 0)
{
- *r->headers_out.location = *loc;
+ *location = *loc;
return NGX_OK;
}
/* TODO: proxy_reverse */
- r->headers_out.location->value.len = uc->location->len
- + (loc->value.len - uc->url.len) + 1;
- r->headers_out.location->value.data =
- ngx_palloc(r->pool, r->headers_out.location->value.len);
-
- if (r->headers_out.location->value.data == NULL) {
+ location->value.len = uc->location->len
+ + (loc->value.len - uc->url.len) + 1;
+ if (!(location->value.data = ngx_palloc(r->pool, location->value.len))) {
return NGX_ERROR;
}
- last = ngx_cpymem(r->headers_out.location->value.data,
+ last = ngx_cpymem(location->value.data,
uc->location->data, uc->location->len);
ngx_cpystrn(last, loc->value.data + uc->url.len,
}
- header = (ngx_table_elt_t *) r->headers_in.headers->elts;
- for (i = 0; i < r->headers_in.headers->nelts; i++) {
+ header = r->headers_in.headers.elts;
+ for (i = 0; i < r->headers_in.headers.nelts; i++) {
if (&header[i] == r->headers_in.host) {
continue;
h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
- if (p->lcf->preserve_host) {
+ if (p->lcf->preserve_host && r->headers_in.host) {
h->last = ngx_cpymem(h->last, r->headers_in.host->value.data,
r->headers_in.host_name_len);
}
- for (i = 0; i < r->headers_in.headers->nelts; i++) {
+ for (i = 0; i < r->headers_in.headers.nelts; i++) {
if (&header[i] == r->headers_in.host) {
continue;
return;
}
- output->output_ctx = writer;
+ output->filter_ctx = writer;
writer->pool = r->pool;
if (p->lcf->busy_lock && !p->busy_locked) {
{
ngx_chain_t *cl;
ngx_output_chain_ctx_t *output;
- ngx_chain_writer_ctx_t *writer;
output = p->upstream->output_chain_ctx;
for (cl = p->request->request_hunks; cl; cl = cl->next) {
cl->hunk->pos = cl->hunk->start;
+ cl->hunk->file_pos = 0;
}
/* reinit the ngx_output_chain() context */
/* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
output = p->upstream->output_chain_ctx;
- writer = output->output_ctx;
+ writer = output->filter_ctx;
writer->out = NULL;
writer->last = &writer->out;
writer->connection = c;
output->hunks = 1;
r->request_body_hunk->pos = r->request_body_hunk->start;
- r->request_body_hunk->last = r->request_body_hunk->start;
}
p->request_sent = 0;
"http proxy status %d \"%s\"",
p->upstream->status, p->upstream->status_line.data);
- if (p->upstream->headers_in.headers) {
- p->upstream->headers_in.headers->nelts = 0;
+
+ /* init or reinit the p->upstream->headers_in.headers table */
+
+ if (p->upstream->headers_in.headers.elts) {
+ p->upstream->headers_in.headers.nelts = 0;
+
} else {
- /* TODO: ngx_init_table */
- p->upstream->headers_in.headers = ngx_create_table(p->request->pool,
- 20);
+ p->upstream->headers_in.headers.elts = ngx_pcalloc(p->request->pool,
+ 20 * sizeof(ngx_table_elt_t));
+ if (p->upstream->headers_in.headers.elts == NULL) {
+ ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+ /* p->upstream->headers_in.headers.nelts = 0; */
+ p->upstream->headers_in.headers.nalloc = 20;
+ p->upstream->headers_in.headers.size = sizeof(ngx_table_elt_t);
+ p->upstream->headers_in.headers.pool = p->request->pool;
}
+
c->read->event_handler = ngx_http_proxy_process_upstream_headers;
ngx_http_proxy_process_upstream_headers(rev);
}
r->connection->tcp_nopush = -1;
}
+
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT,
+ r->headers_in.content_length_n,
+ clcf->client_max_body_size);
+
+ if (r->headers_in.content_length_n != -1
+ && clcf->client_max_body_size
+ && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n)
+ {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "client intented to send too large body: "
+ SIZE_T_FMT " bytes",
+ r->headers_in.content_length_n);
+
+ return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
+ }
+
+
if (auto_redirect) {
if (!(r->headers_out.location =
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
len += sizeof("Connection: closed" CRLF) - 1;
}
- header = r->headers_out.headers->elts;
- for (i = 0; i < r->headers_out.headers->nelts; i++) {
+ header = r->headers_out.headers.elts;
+ for (i = 0; i < r->headers_out.headers.nelts; i++) {
if (header[i].key.len == 0) {
continue;
}
sizeof("Connection: close" CRLF) - 1);
}
- for (i = 0; i < r->headers_out.headers->nelts; i++) {
+ for (i = 0; i < r->headers_out.headers.nelts; i++) {
if (header[i].key.len == 0) {
continue;
}
ngx_table_elt_t *ngx_http_add_header(void *header,
ngx_http_header_t *http_headers)
{
- char *prev;
+ void *prev;
ngx_uint_t i, j;
ngx_table_t *headers;
ngx_table_elt_t *h, *new;
- headers = *(ngx_table_t **) header;
+ headers = header;
prev = headers->elts;
s = (ngx_str_t *) data;
- h = r->headers_in.headers->elts;
- for (i = 0; i < r->headers_in.headers->nelts; i++) {
+ h = r->headers_in.headers.elts;
+ for (i = 0; i < r->headers_in.headers.nelts; i++) {
if (h[i].key.len != s->len) {
continue;
}
s = (ngx_str_t *) data;
- h = r->headers_out.headers->elts;
- for (i = 0; i < r->headers_out.headers->nelts; i++) {
+ h = r->headers_out.headers.elts;
+ for (i = 0; i < r->headers_out.headers.nelts; i++) {
if (h[i].key.len != s->len) {
continue;
}
ctx->output_filter = (ngx_output_chain_filter_pt)
ngx_http_top_body_filter;
- ctx->output_ctx = r;
+ ctx->filter_ctx = r;
}
"client %s sent invalid header, URL: %s",
"client %s sent too long header line, URL: %s",
"client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
- "client %s sent invalid \"Content-Length\" header, URL: %s",
- "client %s wanted to send too large body: " SIZE_T_FMT " bytes, URL: %s"
+ "client %s sent invalid \"Content-Length\" header, URL: %s"
};
r->cleanup.size = sizeof(ngx_http_cleanup_t);
r->cleanup.pool = r->pool;
- /* TODO: ngx_init_table */
- if (!(r->headers_out.headers = ngx_create_table(r->pool, 20))) {
+
+ /* init the r->headers_out.headers table */
+
+ r->headers_out.headers.elts = ngx_pcalloc(r->pool,
+ 20 * sizeof(ngx_table_elt_t));
+ if (r->headers_out.headers.elts == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
}
+ /* r->headers_out.headers.nelts = 0; */
+ r->headers_out.headers.nalloc = 20;
+ r->headers_out.headers.size = sizeof(ngx_table_elt_t);
+ r->headers_out.headers.pool = r->pool;
+
r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) {
return;
}
+
+ /* init the r->headers_in.headers table */
+
+ r->headers_in.headers.elts = ngx_pcalloc(r->pool,
+ 20 * sizeof(ngx_table_elt_t));
+ if (r->headers_in.headers.elts == NULL) {
+ ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ /* r->headers_in.headers.elts = NULL; */
+ /* r->headers_in.headers.nelts = 0; */
+ r->headers_in.headers.size = sizeof(ngx_table_elt_t);
+ r->headers_in.headers.nalloc = 20;
+ r->headers_in.headers.pool = r->pool;
+
ctx = c->log->data;
ctx->action = "reading client request headers";
ctx->url = r->unparsed_uri.data;
- /* TODO: ngx_init_table */
- r->headers_in.headers = ngx_create_table(r->pool, 20);
if (cscf->large_client_header
&& r->header_in->pos == r->header_in->last)
if (r->headers_in.content_length_n == NGX_ERROR) {
return NGX_HTTP_PARSE_INVALID_CL_HEADER;
}
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT,
- r->headers_in.content_length_n,
- clcf->client_max_body_size);
-
- if (clcf->client_max_body_size
- && clcf->client_max_body_size
- < (size_t) r->headers_in.content_length_n)
- {
- return NGX_HTTP_PARSE_ENTITY_TOO_LARGE;
- }
-
}
if (r->headers_in.connection) {
ngx_del_timer(r->connection->write);
}
+ if (rc == NGX_HTTP_CLIENT_CLOSED_REQUEST || r->closed) {
+ ngx_http_close_request(r, 0);
+ ngx_http_close_connection(r->connection);
+ return;
+ }
+
ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));
return;
}
return ngx_http_read_discarded_body(r);
-
- return NGX_OK;
}
n = ngx_recv(r->connection, r->discarded_buffer, size);
if (n == NGX_ERROR) {
- return NGX_HTTP_BAD_REQUEST;
+
+ r->closed = 1;
+
+ /*
+ * when a client request body is discarded then we already set
+ * some HTTP response code for client and we can ignore the error
+ */
+
+ return NGX_OK;
}
if (n == NGX_AGAIN) {
r->connection->log->handler = NULL;
if (ctx->url) {
- if (client_error == NGX_HTTP_PARSE_ENTITY_TOO_LARGE) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
- ctx->client, r->headers_in.content_length_n, ctx->url);
-
- error = NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
- r->lingering_close = 1;
-
- } else {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
ctx->client, ctx->url);
- }
} else {
if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) {
#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
#define NGX_HTTP_PARSE_NO_HOST_HEADER 16
#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
-#define NGX_HTTP_PARSE_ENTITY_TOO_LARGE 18
#define NGX_HTTP_OK 200
typedef struct {
- ngx_table_t *headers; /* it must be first field */
+ ngx_table_t headers; /* it must be first field */
ngx_table_elt_t *host;
ngx_table_elt_t *connection;
typedef struct {
- ngx_table_t *headers; /* it must be first field */
+ ngx_table_t headers; /* it must be first field */
int status;
ngx_str_t status_line;
unsigned header_only:1;
unsigned keepalive:1;
unsigned lingering_close:1;
-#if 0
unsigned closed:1;
-#endif
/* TODO: use the filter flags or the separate bits ???? */
u_int filter;
ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
size_t request_buffer_size)
{
- ngx_int_t rc;
ssize_t size;
ngx_hunk_t *h;
ngx_chain_t *cl;
}
if (n == 0 || n == NGX_ERROR) {
+ r->closed = 1;
return NGX_HTTP_BAD_REQUEST;
}
r->request_body_hunk->last += n;
r->request_body_len -= n;
+ if (r->request_body_len == 0) {
+ break;
+ }
+
if (r->request_body_hunk->last < r->request_body_hunk->end) {
break;
}
rc = ngx_http_discard_body(r);
- if (rc != NGX_OK) {
- return rc;
+ if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
+ error = NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->headers_out.status = error;
extern LPFN_TRANSMITFILE transmitfile;
-static ngx_inline int ngx_tcp_push(ngx_socket_t s) {
+ngx_inline static int ngx_tcp_push(ngx_socket_t s) {
return 0;
}
#include <ngx_auto_config.h>
-#define ngx_inlie __inline
+#define ngx_inline __inline
#ifdef _MSC_VER