Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
170 lines (152 sloc) 5.81 KB
diff -BurN nginx-1.2.5/src/http/ngx_http.c nginx-1.2.5-new/src/http/ngx_http.c
--- nginx-1.2.5/src/http/ngx_http.c 2012-08-07 00:03:56.000000000 +0800
+++ nginx-1.2.5-new/src/http/ngx_http.c 2012-12-07 16:26:42.000000000 +0800
@@ -66,12 +66,18 @@
ngx_http_conf_addr_t *addr);
#endif
+static ngx_int_t ngx_http_dummy_input_body_filter(ngx_http_request_t *r,
+ ngx_buf_t *buf);
+
ngx_uint_t ngx_http_max_module;
ngx_int_t (*ngx_http_top_header_filter) (ngx_http_request_t *r);
ngx_int_t (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
+ngx_int_t (*ngx_http_top_input_body_filter) (ngx_http_request_t *r,
+ ngx_buf_t *buf);
+
ngx_str_t ngx_http_html_default_types[] = {
ngx_string("text/html"),
@@ -218,6 +224,10 @@
pcf = *cf;
cf->ctx = ctx;
+ /* init input body filter pointer */
+
+ ngx_http_top_input_body_filter = ngx_http_dummy_input_body_filter;
+
for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
continue;
@@ -2083,3 +2093,12 @@
return NGX_OK;
}
+
+
+static ngx_int_t
+ngx_http_dummy_input_body_filter(ngx_http_request_t *r, ngx_buf_t *buf)
+{
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http dummy input body filter");
+ return NGX_OK;
+}
diff -BurN nginx-1.2.5/src/http/ngx_http.h nginx-1.2.5-new/src/http/ngx_http.h
--- nginx-1.2.5/src/http/ngx_http.h 2012-01-18 23:07:43.000000000 +0800
+++ nginx-1.2.5-new/src/http/ngx_http.h 2012-12-07 16:11:59.000000000 +0800
@@ -158,4 +158,7 @@
extern ngx_http_output_body_filter_pt ngx_http_top_body_filter;
+extern ngx_http_input_body_filter_pt ngx_http_top_input_body_filter;
+
+
#endif /* _NGX_HTTP_H_INCLUDED_ */
diff -BurN nginx-1.2.5/src/http/ngx_http_core_module.h nginx-1.2.5-new/src/http/ngx_http_core_module.h
--- nginx-1.2.5/src/http/ngx_http_core_module.h 2012-06-04 19:58:12.000000000 +0800
+++ nginx-1.2.5-new/src/http/ngx_http_core_module.h 2012-12-07 16:25:09.000000000 +0800
@@ -505,6 +505,8 @@
typedef ngx_int_t (*ngx_http_output_body_filter_pt)
(ngx_http_request_t *r, ngx_chain_t *chain);
+typedef ngx_int_t (*ngx_http_input_body_filter_pt)
+ (ngx_http_request_t *r, ngx_buf_t *buf);
ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
diff -BurN nginx-1.2.5/src/http/ngx_http_request_body.c nginx-1.2.5-new/src/http/ngx_http_request_body.c
--- nginx-1.2.5/src/http/ngx_http_request_body.c 2012-04-13 03:35:41.000000000 +0800
+++ nginx-1.2.5-new/src/http/ngx_http_request_body.c 2012-12-07 16:11:11.000000000 +0800
@@ -31,7 +30,8 @@
{
size_t preread;
ssize_t size;
- ngx_buf_t *b;
+ ngx_buf_t *b, buf;
+ ngx_int_t rc;
ngx_chain_t *cl, **next;
ngx_temp_file_t *tf;
ngx_http_request_body_t *rb;
@@ -128,6 +128,15 @@
b->last = r->header_in->last;
b->end = r->header_in->end;
+ ngx_memzero(&buf, sizeof(ngx_buf_t));
+ buf.memory = 1;
+ buf.start = r->header_in->pos;
+ buf.pos = r->header_in->pos;
+ buf.last = (off_t) preread >= r->headers_in.content_length_n
+ ? r->header_in->pos + (size_t) r->headers_in.content_length_n
+ : r->header_in->last;
+ buf.end = r->header_in->end;
+
rb->bufs = ngx_alloc_chain_link(r->pool);
if (rb->bufs == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -138,6 +147,27 @@
rb->buf = b;
+ rc = ngx_http_top_input_body_filter(r, &buf);
+ if (rc != NGX_OK) {
+ if (rc > NGX_OK && rc < NGX_HTTP_SPECIAL_RESPONSE) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "input filter: return code 1xx or 2xx "
+ "will cause trouble and is converted to 500");
+ }
+
+ /**
+ * NGX_OK: success and continue;
+ * NGX_ERROR: failed and exit;
+ * NGX_AGAIN: not ready and retry later.
+ */
+
+ if (rc < NGX_HTTP_SPECIAL_RESPONSE && rc != NGX_AGAIN) {
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ return rc;
+ }
+
if ((off_t) preread >= r->headers_in.content_length_n) {
/* the whole request body was pre-read */
@@ -263,7 +293,8 @@
{
size_t size;
ssize_t n;
- ngx_buf_t *b;
+ ngx_buf_t *b, buf;
+ ngx_int_t rc;
ngx_connection_t *c;
ngx_http_request_body_t *rb;
ngx_http_core_loc_conf_t *clcf;
@@ -311,10 +342,32 @@
return NGX_HTTP_BAD_REQUEST;
}
+ ngx_memzero(&buf, sizeof(ngx_buf_t));
+ buf.memory = 1;
+ buf.start = rb->buf->last;
+ buf.pos = rb->buf->last;
+ buf.last = buf.start + n;
+ buf.end = buf.last;
+
rb->buf->last += n;
rb->rest -= n;
r->request_length += n;
+ rc = ngx_http_top_input_body_filter(r, &buf);
+ if (rc != NGX_OK) {
+ if (rc > NGX_OK && rc < NGX_HTTP_SPECIAL_RESPONSE) {
+ ngx_log_error(NGX_LOG_ERR, c->log, 0,
+ "input filter: return code 1xx or 2xx "
+ "will cause trouble and is converted to 500");
+ }
+
+ if (rc < NGX_HTTP_SPECIAL_RESPONSE && rc != NGX_AGAIN) {
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ return rc;
+ }
+
if (rb->rest == 0) {
break;
}