Merge branch 'nghttpx-better-early-final-response-handling'

This commit is contained in:
Tatsuhiro Tsujikawa 2016-12-24 23:02:52 +09:00
commit e6b4454e48
5 changed files with 49 additions and 7 deletions

View File

@ -2022,7 +2022,12 @@ int Http2Session::write_clear() {
} }
if (nwrite < 0) { if (nwrite < 0) {
return nwrite; // We may have pending data in receive buffer which may
// contain part of response body. So keep reading. Invoke
// read event to get read(2) error just in case.
ev_feed_event(conn_.loop, &conn_.rev, EV_READ);
wb_.drain(wb_.rleft());
break;
} }
wb_.drain(nwrite); wb_.drain(nwrite);
@ -2132,7 +2137,12 @@ int Http2Session::write_tls() {
} }
if (nwrite < 0) { if (nwrite < 0) {
return nwrite; // We may have pending data in receive buffer which may
// contain part of response body. So keep reading. Invoke
// read event to get read(2) error just in case.
ev_feed_event(conn_.loop, &conn_.rev, EV_READ);
wb_.drain(wb_.rleft());
break;
} }
wb_.drain(nwrite); wb_.drain(nwrite);

View File

@ -1854,6 +1854,11 @@ int Http2Upstream::on_downstream_reset(Downstream *downstream, bool no_retry) {
} }
if (!downstream->request_submission_ready()) { if (!downstream->request_submission_ready()) {
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
// We have got all response body already. Send it off.
downstream->pop_downstream_connection();
return 0;
}
// pushed stream is handled here // pushed stream is handled here
rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); rst_stream(downstream, NGHTTP2_INTERNAL_ERROR);
downstream->pop_downstream_connection(); downstream->pop_downstream_connection();

View File

@ -1116,7 +1116,12 @@ int HttpDownstreamConnection::write_clear() {
} }
if (nwrite < 0) { if (nwrite < 0) {
return nwrite; // We may have pending data in receive buffer which may contain
// part of response body. So keep reading. Invoke read event
// to get read(2) error just in case.
ev_feed_event(conn_.loop, &conn_.rev, EV_READ);
input->drain(input->rleft());
break;
} }
input->drain(nwrite); input->drain(nwrite);
@ -1236,7 +1241,12 @@ int HttpDownstreamConnection::write_tls() {
} }
if (nwrite < 0) { if (nwrite < 0) {
return nwrite; // We may have pending data in receive buffer which may contain
// part of response body. So keep reading. Invoke read event
// to get read(2) error just in case.
ev_feed_event(conn_.loop, &conn_.rev, EV_READ);
input->drain(input->rleft());
break;
} }
input->drain(nwrite); input->drain(nwrite);

View File

@ -1197,7 +1197,9 @@ int HttpsUpstream::on_downstream_body_complete(Downstream *downstream) {
resp.connection_close = true; resp.connection_close = true;
} }
if (req.connection_close || resp.connection_close) { if (req.connection_close || resp.connection_close ||
// To avoid to stall upload body
downstream->get_request_state() != Downstream::MSG_COMPLETE) {
auto handler = get_client_handler(); auto handler = get_client_handler();
handler->set_should_close_after_write(true); handler->set_should_close_after_write(true);
} }
@ -1234,13 +1236,23 @@ int HttpsUpstream::on_downstream_reset(Downstream *downstream, bool no_retry) {
assert(downstream == downstream_.get()); assert(downstream == downstream_.get());
downstream_->pop_downstream_connection();
if (!downstream_->request_submission_ready()) { if (!downstream_->request_submission_ready()) {
switch (downstream_->get_response_state()) {
case Downstream::MSG_COMPLETE:
// We have got all response body already. Send it off.
return 0;
case Downstream::INITIAL:
if (on_downstream_abort_request(downstream_.get(), 503) != 0) {
return -1;
}
return 0;
}
// Return error so that caller can delete handler // Return error so that caller can delete handler
return -1; return -1;
} }
downstream_->pop_downstream_connection();
downstream_->add_retry(); downstream_->add_retry();
if (no_retry || downstream_->no_more_retry()) { if (no_retry || downstream_->no_more_retry()) {

View File

@ -1314,6 +1314,11 @@ int SpdyUpstream::on_downstream_reset(Downstream *downstream, bool no_retry) {
} }
if (!downstream->request_submission_ready()) { if (!downstream->request_submission_ready()) {
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
// We have got all response body already. Send it off.
downstream->pop_downstream_connection();
return 0;
}
rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); rst_stream(downstream, SPDYLAY_INTERNAL_ERROR);
downstream->pop_downstream_connection(); downstream->pop_downstream_connection();