diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 45b522b2..c14c5eaf 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -115,11 +115,10 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, int32_t stream_id, int32_t priority) : dlnext(nullptr), dlprev(nullptr), request_start_time_(std::chrono::high_resolution_clock::now()), - request_buf_(mcpool), response_buf_(mcpool), request_bodylen_(0), - response_bodylen_(0), response_sent_bodylen_(0), upstream_(upstream), - blocked_link_(nullptr), request_datalen_(0), response_datalen_(0), - num_retry_(0), stream_id_(stream_id), priority_(priority), - downstream_stream_id_(-1), + request_buf_(mcpool), response_buf_(mcpool), response_bodylen_(0), + response_sent_bodylen_(0), upstream_(upstream), blocked_link_(nullptr), + request_datalen_(0), response_datalen_(0), num_retry_(0), + stream_id_(stream_id), priority_(priority), downstream_stream_id_(-1), response_rst_stream_error_code_(NGHTTP2_NO_ERROR), request_state_(INITIAL), response_state_(INITIAL), dispatch_state_(DISPATCH_NONE), upgraded_(false), chunked_request_(false), @@ -518,7 +517,7 @@ int Downstream::push_upload_data_chunk(const uint8_t *data, size_t datalen) { DLOG(INFO, this) << "dconn_ is NULL"; return -1; } - request_bodylen_ += datalen; + req_.recv_body_length += datalen; if (dconn_->push_upload_data_chunk(data, datalen) != 0) { return -1; } @@ -643,16 +642,16 @@ int64_t Downstream::get_response_sent_bodylen() const { return response_sent_bodylen_; } -bool Downstream::validate_request_bodylen() const { +bool Downstream::validate_request_recv_body_length() const { if (req_.fs.content_length == -1) { return true; } - if (req_.fs.content_length != request_bodylen_) { + if (req_.fs.content_length != req_.recv_body_length) { if (LOG_ENABLED(INFO)) { DLOG(INFO, this) << "request invalid bodylen: content-length=" << req_.fs.content_length - << ", received=" << request_bodylen_; + << ", received=" << req_.recv_body_length; } return false; } diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 3bfc73a2..8c80d1a2 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -124,7 +124,7 @@ private: struct Request { Request() - : fs(16), method(-1), http_major(1), http_minor(1), + : fs(16), recv_body_length(0), method(-1), http_major(1), http_minor(1), upgrade_request(false), http2_upgrade_seen(false), connection_close(false), http2_expect_body(false) {} @@ -142,6 +142,8 @@ struct Request { // request-target. For HTTP/2, this is :path header field value. // For CONNECT request, this is empty. std::string path; + // the length of request body received so far + int64_t recv_body_length; int method; // HTTP major and minor version int http_major, http_minor; @@ -239,7 +241,7 @@ public: void reset_request_datalen(); // Validates that received request body length and content-length // matches. - bool validate_request_bodylen() const; + bool validate_request_recv_body_length() const; void set_request_downstream_host(std::string host); bool expect_response_body() const; enum { @@ -390,8 +392,6 @@ private: ev_timer downstream_rtimer_; ev_timer downstream_wtimer_; - // the length of request body received so far - int64_t request_bodylen_; // the length of response body received so far int64_t response_bodylen_; diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 0fb7fd59..e518b568 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -263,7 +263,7 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type, #endif // HAVE_MRUBY if (frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - if (!downstream->validate_request_bodylen()) { + if (!downstream->validate_request_recv_body_length()) { upstream->rst_stream(downstream, SPDYLAY_PROTOCOL_ERROR); return; } @@ -386,7 +386,7 @@ void on_data_recv_callback(spdylay_session *session, uint8_t flags, auto downstream = static_cast( spdylay_session_get_stream_user_data(session, stream_id)); if (downstream && (flags & SPDYLAY_DATA_FLAG_FIN)) { - if (!downstream->validate_request_bodylen()) { + if (!downstream->validate_request_recv_body_length()) { upstream->rst_stream(downstream, SPDYLAY_PROTOCOL_ERROR); return; }