Thanks Maxim.<br><br>I <span style="color:rgb(0, 0, 0);font-family:'Microsoft YaHei';font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:nowrap;word-spacing:0px">ignore half-close connection, so fix this. </span><br>
<br>Index: src/http/ngx_http_request_body.c<br>===================================================================<br>--- src/http/ngx_http_request_body.c (revision 4146)<br>+++ src/http/ngx_http_request_body.c (working copy)<br>
@@ -438,6 +438,7 @@<br> ngx_http_discard_request_body(ngx_http_request_t *r)<br> {<br> ssize_t size;<br>+ ngx_int_t rc;<br> ngx_event_t *rev;<br> <br> if (r != r->main || r->discard_body) {<br>
@@ -476,18 +477,37 @@<br> <br> r->read_event_handler = ngx_http_discarded_request_body_handler;<br> <br>- if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>- return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>+ rc = ngx_http_read_discarded_request_body(r);<br>
+<br>+ if (rc == NGX_ERROR) {<br>+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br> }<br> <br>- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>+ if (rc == NGX_DONE || rc == NGX_OK) {<br> r->lingering_close = 0;<br>
+ }<br> <br>- } else {<br>+ if (rc == NGX_OK) {<br>+ if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {<br>+ if (ngx_del_event(rev, NGX_READ_EVENT, 0) != NGX_OK) {<br>
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
+ }<br>+ }<br>+<br>+ return NGX_OK;<br>+ }<br>+<br>+ if (rc == NGX_AGAIN) {<br> r->count++;<br> r->discard_body = 1;<br> }<br> <br>+ /* NGX_AGAIN or NGX_DONE */<br>
+<br>+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>+ return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>+ }<br>+<br> return NGX_OK;<br> }<br> <br>@@ -527,7 +547,22 @@<br> <br> rc = ngx_http_read_discarded_request_body(r);<br>
<br>+ if (rc == NGX_ERROR) {<br>+ ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>+ return;<br>+ }<br>+<br> if (rc == NGX_OK) {<br>+ if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {<br>
+ if (ngx_del_event(rev, NGX_READ_EVENT, 0) != NGX_OK) {<br>+ c->error = 1;<br>+ ngx_http_finalize_request(r, NGX_ERROR);<br>+ return;<br>+ }<br>+ }<br>
+ }<br>+<br>+ if (rc == NGX_OK || rc == NGX_DONE) {<br> r->discard_body = 0;<br> r->lingering_close = 0;<br> ngx_http_finalize_request(r, NGX_DONE);<br>@@ -570,7 +605,7 @@<br> for ( ;; ) {<br>
if (r->headers_in.content_length_n == 0) {<br> r->read_event_handler = ngx_http_block_reading;<br>- return NGX_OK;<br>+ return NGX_DONE;<br> }<br> <br> if (!r->connection->read->ready) {<br>
@@ -585,7 +620,7 @@<br> <br> if (n == NGX_ERROR) {<br> r->connection->error = 1;<br>- return NGX_OK;<br>+ return NGX_ERROR;<br> }<br> <br> if (n == NGX_AGAIN) {<br>
<br><br><br><br><div class="gmail_quote">On Tue, Sep 27, 2011 at 4:04 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<div><br>
On Tue, Sep 27, 2011 at 02:48:15PM +0800, Simon Liu wrote:<br>
<br>
> change: use ngx_int_t replace int.<br>
><br>
> Index: src/http/ngx_http_request_body.c<br>
> ===================================================================<br>
> --- src/http/ngx_http_request_body.c (revision 4146)<br>
> +++ src/http/ngx_http_request_body.c (working copy)<br>
> @@ -438,6 +438,7 @@<br>
> ngx_http_discard_request_body(ngx_http_request_t *r)<br>
> {<br>
> ssize_t size;<br>
> + ngx_int_t rc;<br>
> ngx_event_t *rev;<br>
><br>
> if (r != r->main || r->discard_body) {<br>
> @@ -476,11 +477,13 @@<br>
><br>
> r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
><br>
> - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + rc = ngx_http_read_discarded_request_body(r);<br>
> +<br>
> + if (rc == NGX_ERROR) {<br>
> + return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br>
<br>
</div>I don't think that returing NGX_HTTP_CLIENT_CLOSED_REQUEST here is<br>
a good idea. There are clients out there which half-close<br>
connection after sending request, and this would break such<br>
clients.<br>
<br>
Maxim Dounin<br>
<br>
> }<br>
><br>
> - if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
<div><div></div><div>> + if (rc == NGX_OK) {<br>
> r->lingering_close = 0;<br>
><br>
> } else {<br>
> @@ -488,6 +491,10 @@<br>
> r->discard_body = 1;<br>
> }<br>
><br>
> + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + }<br>
> +<br>
> return NGX_OK;<br>
> }<br>
><br>
> @@ -527,6 +534,11 @@<br>
><br>
> rc = ngx_http_read_discarded_request_body(r);<br>
><br>
> + if (rc == NGX_ERROR) {<br>
> + ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>
> + return;<br>
> + }<br>
> +<br>
> if (rc == NGX_OK) {<br>
> r->discard_body = 0;<br>
> r->lingering_close = 0;<br>
> @@ -583,19 +595,15 @@<br>
><br>
> n = r->connection->recv(r->connection, buffer, size);<br>
><br>
> - if (n == NGX_ERROR) {<br>
> + if (n == 0 || n == NGX_ERROR) {<br>
> r->connection->error = 1;<br>
> - return NGX_OK;<br>
> + return NGX_ERROR;<br>
> }<br>
><br>
> if (n == NGX_AGAIN) {<br>
> return NGX_AGAIN;<br>
> }<br>
><br>
> - if (n == 0) {<br>
> - return NGX_OK;<br>
> - }<br>
> -<br>
> r->headers_in.content_length_n -= n;<br>
> }<br>
> }<br>
><br>
><br>
> On Tue, Sep 27, 2011 at 2:42 PM, Simon Liu <<a href="mailto:simohayha.bobo@gmail.com" target="_blank">simohayha.bobo@gmail.com</a>> wrote:<br>
><br>
> > Sorry, I have mistake.<br>
> ><br>
> > This is correct patch:<br>
> ><br>
> ><br>
> > Index: src/http/ngx_http_request_body.c<br>
> > ===================================================================<br>
> > --- src/http/ngx_http_request_body.c (revision 4146)<br>
> > +++ src/http/ngx_http_request_body.c (working copy)<br>
> > @@ -437,6 +437,7 @@<br>
> > ngx_int_t<br>
> > ngx_http_discard_request_body(ngx_http_request_t *r)<br>
> > {<br>
> > + int rc;<br>
> > ssize_t size;<br>
> > ngx_event_t *rev;<br>
> ><br>
> > @@ -476,11 +477,13 @@<br>
> ><br>
> ><br>
> > r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
> ><br>
> > - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> > - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> > + rc = ngx_http_read_discarded_request_body(r);<br>
> > +<br>
> > + if (rc == NGX_ERROR) {<br>
> > + return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br>
> > }<br>
> ><br>
> > - if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> > + if (rc == NGX_OK) {<br>
> > r->lingering_close = 0;<br>
> ><br>
> > } else {<br>
> > @@ -488,6 +491,10 @@<br>
> ><br>
> > r->discard_body = 1;<br>
> > }<br>
> ><br>
> > + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> > + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> > + }<br>
> > +<br>
> > return NGX_OK;<br>
> > }<br>
> ><br>
> > @@ -527,6 +534,11 @@<br>
> ><br>
> ><br>
> > rc = ngx_http_read_discarded_request_body(r);<br>
> ><br>
> > + if (rc == NGX_ERROR) {<br>
> > + ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>
> > + return;<br>
> > + }<br>
> > +<br>
> > if (rc == NGX_OK) {<br>
> > r->discard_body = 0;<br>
> > r->lingering_close = 0;<br>
> > @@ -583,19 +595,15 @@<br>
> ><br>
> ><br>
> > n = r->connection->recv(r->connection, buffer, size);<br>
> ><br>
> > - if (n == NGX_ERROR) {<br>
> > + if (n == 0 || n == NGX_ERROR) {<br>
> > r->connection->error = 1;<br>
> > - return NGX_OK;<br>
> > + return NGX_ERROR;<br>
> > }<br>
> ><br>
> > if (n == NGX_AGAIN) {<br>
> > return NGX_AGAIN;<br>
> > }<br>
> ><br>
> > - if (n == 0) {<br>
> > - return NGX_OK;<br>
> > - }<br>
> > -<br>
> > r->headers_in.content_length_n -= n;<br>
> > }<br>
> > }<br>
> ><br>
> ><br>
> ><br>
> > On Tue, Sep 27, 2011 at 2:33 PM, Simon Liu <<a href="mailto:simohayha.bobo@gmail.com" target="_blank">simohayha.bobo@gmail.com</a>>wrote:<br>
> ><br>
> >> Thanks Maxim.<br>
> >><br>
> >> This is new patch, I think this may be better.<br>
> >><br>
> >> I think ngx_handle_read_event can't be avoid(in<br>
> >> ngx_http_discard_request_body), because it doesn't known whether or not<br>
> >> need to add read event in ngx_http_discard_request_body. So there need<br>
> >> ngx_handle_read_event to judge.<br>
> >><br>
> >><br>
> >> Index: src/http/ngx_http_request_body.c<br>
> >> ===================================================================<br>
> >> --- src/http/ngx_http_request_body.c (revision 4146)<br>
> >> +++ src/http/ngx_http_request_body.c (working copy)<br>
> >> @@ -476,11 +476,13 @@<br>
> >><br>
> >><br>
> >> r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
> >><br>
> >> - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >> - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >> + rc = ngx_http_read_discarded_request_body(r);<br>
> >> +<br>
> >> + if (rc == NGX_ERROR) {<br>
> >> + return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br>
> >> }<br>
> >><br>
> >> - if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> >> + if (rc == NGX_OK) {<br>
> >> r->lingering_close = 0;<br>
> >><br>
> >> } else {<br>
> >> @@ -488,6 +490,10 @@<br>
> >><br>
> >> r->discard_body = 1;<br>
> >> }<br>
> >><br>
> >> + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >> + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >> + }<br>
> >> +<br>
> >> return NGX_OK;<br>
> >> }<br>
> >><br>
> >> @@ -527,6 +533,11 @@<br>
> >><br>
> >> rc = ngx_http_read_discarded_request_body(r);<br>
> >><br>
> >> + if (rc == NGX_ERROR) {<br>
> >> + ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>
> >> + return;<br>
> >> + }<br>
> >> +<br>
> >> if (rc == NGX_OK) {<br>
> >> r->discard_body = 0;<br>
> >> r->lingering_close = 0;<br>
> >> @@ -583,19 +594,15 @@<br>
> >><br>
> >> n = r->connection->recv(r->connection, buffer, size);<br>
> >><br>
> >> - if (n == NGX_ERROR) {<br>
> >> + if (n == 0 || n == NGX_ERROR) {<br>
> >> r->connection->error = 1;<br>
> >> - return NGX_OK;<br>
> >> + return NGX_ERROR;<br>
> >> }<br>
> >><br>
> >> if (n == NGX_AGAIN) {<br>
> >> return NGX_AGAIN;<br>
> >> }<br>
> >><br>
> >> - if (n == 0) {<br>
> >> - return NGX_OK;<br>
> >> - }<br>
> >> -<br>
> >> r->headers_in.content_length_n -= n;<br>
> >><br>
> >> }<br>
> >> }<br>
> >><br>
> >><br>
> >> On Mon, Sep 26, 2011 at 11:50 PM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>>wrote:<br>
> >><br>
> >>> Hello!<br>
> >>><br>
> >>> On Mon, Sep 26, 2011 at 11:34:42PM +0800, Simon Liu wrote:<br>
> >>><br>
> >>> > Thanks .<br>
> >>> ><br>
> >>> > This is patch:<br>
> >>> ><br>
> >>> > Index: src/http/ngx_http_request_body.c<br>
> >>> > ===================================================================<br>
> >>> > --- src/http/ngx_http_request_body.c (revision 4146)<br>
> >>> > +++ src/http/ngx_http_request_body.c (working copy)<br>
> >>> > @@ -476,10 +476,6 @@<br>
> >>> ><br>
> >>> > r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
> >>> ><br>
> >>> > - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >>> > - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >>> > - }<br>
> >>> > -<br>
> >>> > if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> >>> > r->lingering_close = 0;<br>
> >>> ><br>
> >>> > @@ -488,6 +484,10 @@<br>
> >>> > r->discard_body = 1;<br>
> >>> > }<br>
> >>> ><br>
> >>> > + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >>> > + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >>> > + }<br>
> >>> > +<br>
> >>> > return NGX_OK;<br>
> >>> > }<br>
> >>><br>
> >>> It's better to avoid ngx_handle_read_event() altogether in<br>
> >>> case ngx_http_read_discarded_request_body() returns NGX_OK (i.e.<br>
> >>> everything is read, no futher actions required).<br>
> >>><br>
> >>> It would be a bit more readable and slightly more optimal.<br>
> >>><br>
> >>> Maxim Dounin<br>
> >>><br>
> >>> ><br>
> >>> ><br>
> >>> > On Mon, Sep 26, 2011 at 11:08 PM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>><br>
> >>> wrote:<br>
> >>> ><br>
> >>> > > Hello!<br>
> >>> > ><br>
> >>> > > On Mon, Sep 26, 2011 at 10:42:20PM +0800, Simon Liu wrote:<br>
> >>> > ><br>
> >>> > > > Hi all.<br>
> >>> > > ><br>
> >>> > > > My nginx version is svn trunk.<br>
> >>> > > ><br>
> >>> > > > Nginx will call ngx_handle_read_event, and then<br>
> >>> > > > call ngx_http_read_discarded_request_body In<br>
> >>> > > ngx_http_discard_request_body .<br>
> >>> > > > So this will cause client's body read incomplete data , because<br>
> >>> > > > ngx_handle_read_event<br>
> >>> > > > may delete read event when use level event.<br>
> >>> > > ><br>
> >>> > > > ngx_handle_read_event:<br>
> >>> > > ><br>
> >>> > > > else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {<br>
> >>> > > ><br>
> >>> > > > /* select, poll, /dev/poll */<br>
> >>> > > > .................................................................<br>
> >>> > > ><br>
> >>> > > > if (rev->active && (rev->ready || (flags &<br>
> >>> NGX_CLOSE_EVENT))) {<br>
> >>> > > > if (ngx_del_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT<br>
> >>> |<br>
> >>> > > flags)<br>
> >>> > > > == NGX_ERROR)<br>
> >>> > > > {<br>
> >>> > > > return NGX_ERROR;<br>
> >>> > > > }<br>
> >>> > > ><br>
> >>> > > > return NGX_OK;<br>
> >>> > > > }<br>
> >>> > > ><br>
> >>> > > ><br>
> >>> > > > ngx_http_discard_request_body:<br>
> >>> > > ><br>
> >>> > > > r->read_event_handler =<br>
> >>> ngx_http_discarded_request_body_handler;<br>
> >>> > > ><br>
> >>> > > > if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >>> > > > return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >>> > > > }<br>
> >>> > > ><br>
> >>> > > > if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> >>> > > > r->lingering_close = 0;<br>
> >>> > > ><br>
> >>> > > ><br>
> >>> > > > thanks!<br>
> >>> > ><br>
> >>> > > Ack, ngx_handle_read_event() should be after<br>
> >>> > > ngx_http_read_discarded_request_body() call, like it's done in<br>
> >>> > > ngx_http_discarded_request_body_handler().<br>
> >>> > ><br>
> >>> > > Care to provide patch?<br>
> >>> > ><br>
> >>> > > Maxim Dounin<br>
> >>> > ><br>
> >>> > > _______________________________________________<br>
> >>> > > nginx-devel mailing list<br>
> >>> > > <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> >>> > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
> >>> > ><br>
> >>><br>
> >>> > Index: src/http/ngx_http_request_body.c<br>
> >>> > ===================================================================<br>
> >>> > --- src/http/ngx_http_request_body.c (revision 4146)<br>
> >>> > +++ src/http/ngx_http_request_body.c (working copy)<br>
> >>> > @@ -476,10 +476,6 @@<br>
> >>> ><br>
> >>> > r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
> >>> ><br>
> >>> > - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >>> > - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >>> > - }<br>
> >>> > -<br>
> >>> > if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> >>> > r->lingering_close = 0;<br>
> >>> ><br>
> >>> > @@ -488,6 +484,10 @@<br>
> >>> > r->discard_body = 1;<br>
> >>> > }<br>
> >>> ><br>
> >>> > + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> >>> > + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> >>> > + }<br>
> >>> > +<br>
> >>> > return NGX_OK;<br>
> >>> > }<br>
> >>> ><br>
> >>><br>
> >>> > _______________________________________________<br>
> >>> > nginx-devel mailing list<br>
> >>> > <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> >>> > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
> >>><br>
> >>> _______________________________________________<br>
> >>> nginx-devel mailing list<br>
> >>> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> >>> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
> >>><br>
> >><br>
> >><br>
> >><br>
> >> --<br>
> >> douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>
> >><br>
> >><br>
> >> blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
> >><br>
> >> twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br>
> >><br>
> >> weibo: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
> >><br>
> >><br>
> ><br>
> ><br>
> > --<br>
> > 博观约取<br>
> ><br>
> > 豆瓣:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>
> ><br>
> ><br>
> > blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
> ><br>
> > twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br>
> ><br>
> > sina 微博: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
> ><br>
> ><br>
><br>
><br>
> --<br>
><br>
> douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>
><br>
> blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
><br>
> twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br>
><br>
> sina: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
<br>
> Index: src/http/ngx_http_request_body.c<br>
> ===================================================================<br>
> --- src/http/ngx_http_request_body.c (revision 4146)<br>
> +++ src/http/ngx_http_request_body.c (working copy)<br>
> @@ -438,6 +438,7 @@<br>
> ngx_http_discard_request_body(ngx_http_request_t *r)<br>
> {<br>
> ssize_t size;<br>
> + ngx_int_t rc;<br>
> ngx_event_t *rev;<br>
><br>
> if (r != r->main || r->discard_body) {<br>
> @@ -476,11 +477,13 @@<br>
><br>
> r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
><br>
> - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + rc = ngx_http_read_discarded_request_body(r);<br>
> +<br>
> + if (rc == NGX_ERROR) {<br>
> + return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br>
> }<br>
><br>
> - if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> + if (rc == NGX_OK) {<br>
> r->lingering_close = 0;<br>
><br>
> } else {<br>
> @@ -488,6 +491,10 @@<br>
> r->discard_body = 1;<br>
> }<br>
><br>
> + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + }<br>
> +<br>
> return NGX_OK;<br>
> }<br>
><br>
> @@ -527,6 +534,11 @@<br>
><br>
> rc = ngx_http_read_discarded_request_body(r);<br>
><br>
> + if (rc == NGX_ERROR) {<br>
> + ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>
> + return;<br>
> + }<br>
> +<br>
> if (rc == NGX_OK) {<br>
> r->discard_body = 0;<br>
> r->lingering_close = 0;<br>
> @@ -583,19 +595,15 @@<br>
><br>
> n = r->connection->recv(r->connection, buffer, size);<br>
><br>
> - if (n == NGX_ERROR) {<br>
> + if (n == 0 || n == NGX_ERROR) {<br>
> r->connection->error = 1;<br>
> - return NGX_OK;<br>
> + return NGX_ERROR;<br>
> }<br>
><br>
> if (n == NGX_AGAIN) {<br>
> return NGX_AGAIN;<br>
> }<br>
><br>
> - if (n == 0) {<br>
> - return NGX_OK;<br>
> - }<br>
> -<br>
> r->headers_in.content_length_n -= n;<br>
> }<br>
> }<br>
<br>
> _______________________________________________<br>
> nginx-devel mailing list<br>
> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></div></div></blockquote></div><br><br clear="all"><br>-- <br>douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>
<br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br><br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br><br>weibo: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
<br>