Forum: NGINX request body problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dr-dr xp (Guest)
on 2009-04-22 07:37
(Received via mailing list)
I do not know if it is a bug or design intention: if request body client
sent is larger than the amount Content-Length specified . The addition
data
is also received and dealt in an incorrect way.

If content-length is smaller :
1) sending a PUT request to webdav module, addition data is written also
in
to file.

2) proxy module behave wrongly, it closes client connection.

To avoid such problems:

@@ -1,4 +1,3 @@
-
 /*
  * Copyright (C) Igor S.
  */
@@ -133,9 +132,12 @@ ngx_http_read_client_request_body(ngx_ht
         rb->buf = b;

         if ((off_t) preread >= r->headers_in.content_length_n) {
-
             /* the whole request body was pre-read */

+            b->last = b->pos + r->headers_in.content_length_n;
+            preread = r->headers_in.content_length_n;
+
+
             r->header_in->pos += (size_t)
r->headers_in.content_length_n;
             r->request_length += r->headers_in.content_length_n;

@@ -267,8 +269,17 @@ ngx_http_do_read_client_request_body(ngx
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http read client request body");

+
     for ( ;; ) {
-        for ( ;; ) {
+      if (rb->rest == 0) {
+        /* dicard */
+        char buf[1024];
+        n = 1;
+        while (n > 0)
+          n = c->recv(c, buf, 1024);
+        return NGX_OK;
+      }
+        for ( ;rb->rest != 0; ) {
             if (rb->buf->last == rb->buf->end) {

                 if (ngx_http_write_request_body(r, rb->to_write) !=
NGX_OK)
{
This topic is locked and can not be replied to.