Sub-request using Parent Request Body

Roman Vasilyev roman at anchorfree.com
Tue Jan 4 05:57:05 MSK 2011


Hello,

I'm trying to make POST analyzer module. To have ability with SPAM 
detection for passing throw traffic, for this I need to have 
request_body in subrequest,  for that I took agentzh / nginx-eval-module

http://forum.nginx.org/read.php?2,84026,84605

and after reading this posts made small changes (please find it below)
on small tests it working fine, but on something with big POSTs it 
loosing information, could somebody help me with understanding how 
better fix this.

--- ngx_http_eval_module.c    2010-12-19 19:55:08.000000000 -0800
+++ ngx_http_eval_module.c.new    2011-01-03 11:39:36.000000000 -0800
@@ -155,6 +155,11 @@
      NGX_MODULE_V1_PADDING
  };

+void
+ngx_http_stub(ngx_http_request_t *r)
+{
+}
+
  static ngx_int_t
  ngx_http_eval_handler(ngx_http_request_t *r)
  {
@@ -261,7 +266,23 @@
          return rc;
      }

-    sr->discard_body = 1;
+        rc = ngx_http_read_client_request_body(r, ngx_http_stub);
+
+        if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+            return rc;
+        }
+
+    ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
+        "eval: request_body \"%p\"", r->request_body);
+        if (r->request_body) {
+            sr->request_body = ngx_palloc(r->pool, 
sizeof(ngx_http_request_body_t));
+            if (sr->request_body == NULL) {
+                return NGX_ERROR;
+            }
+            ngx_memcpy(sr->request_body, r->request_body, 
sizeof(ngx_http_request_body_t));
+        } else {
+            sr->discard_body = 1;
+        }

      ctx->in_progress = 1;





More information about the nginx mailing list