diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 87732d18772..bc107069875 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -180,12 +180,14 @@ rcv_data_frame(Http2ConnectionState &cstate, const Http2Frame &frame) if (nbytes + read_len > unpadded_length) { read_len -= nbytes + read_len - unpadded_length; } - nbytes += writer->write(myreader, read_len); - myreader->consume(nbytes); + int num_written = writer->write(myreader, read_len); + nbytes += num_written; + myreader->consume(num_written); + stream->update_read(num_written); } myreader->writer()->dealloc_reader(myreader); - if (frame.header().flags & HTTP2_FLAGS_DATA_END_STREAM) { + if (frame.header().flags & HTTP2_FLAGS_DATA_END_STREAM || stream->read_vio_done()) { // TODO: set total written size to read_vio.nbytes stream->signal_read_event(VC_EVENT_READ_COMPLETE); } else { diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index 4c420d0e1a9..7620843f3ab 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -213,7 +213,7 @@ Http2Stream::send_request(Http2ConnectionState &cstate) return; } - if (this->recv_end_stream) { + if (this->recv_end_stream || this->read_vio.ntodo() == 0) { this->read_vio.nbytes = bufindex; this->signal_read_event(VC_EVENT_READ_COMPLETE); } else { diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h index cc8bffc2c43..ea7184d834f 100644 --- a/proxy/http2/Http2Stream.h +++ b/proxy/http2/Http2Stream.h @@ -124,6 +124,8 @@ class Http2Stream : public ProxyTransaction bool has_trailing_header() const; void set_request_headers(HTTPHdr &h2_headers); MIOBuffer *read_vio_writer() const; + bool read_vio_done() const; + void update_read(int num_written); ////////////////// // Variables @@ -326,3 +328,15 @@ Http2Stream::read_vio_writer() const { return this->read_vio.get_writer(); } + +inline void +Http2Stream::update_read(int num_written) +{ + read_vio.ndone += num_written; +} + +inline bool +Http2Stream::read_vio_done() const +{ + return read_vio.ntodo() == 0; +}