diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 7e7a750d..c4290e2b 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -834,7 +834,7 @@ void ClientHandler::write_accesslog(Downstream *downstream) { std::chrono::high_resolution_clock::now(), // request_end_time req.http_major, req.http_minor, resp.http_status, - downstream->get_response_sent_bodylen(), port_.c_str(), + downstream->response_sent_body_length, port_.c_str(), get_config()->port, get_config()->pid, }); } diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index c4f8dec6..986526c6 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -113,11 +113,11 @@ void downstream_wtimeoutcb(struct ev_loop *loop, ev_timer *w, int revents) { // upstream could be nullptr for unittests Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, int32_t stream_id, int32_t priority) - : dlnext(nullptr), dlprev(nullptr), + : dlnext(nullptr), dlprev(nullptr), response_sent_body_length(0), request_start_time_(std::chrono::high_resolution_clock::now()), - request_buf_(mcpool), response_buf_(mcpool), response_sent_bodylen_(0), - upstream_(upstream), blocked_link_(nullptr), num_retry_(0), - stream_id_(stream_id), priority_(priority), downstream_stream_id_(-1), + request_buf_(mcpool), response_buf_(mcpool), upstream_(upstream), + blocked_link_(nullptr), 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), @@ -627,14 +627,6 @@ bool Downstream::response_buf_full() { } } -void Downstream::add_response_sent_bodylen(size_t amount) { - response_sent_bodylen_ += amount; -} - -int64_t Downstream::get_response_sent_bodylen() const { - return response_sent_bodylen_; -} - bool Downstream::validate_request_recv_body_length() const { if (req_.fs.content_length == -1) { return true; diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index c267096a..785071cb 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -297,8 +297,6 @@ public: int get_response_state() const; DefaultMemchunks *get_response_buf(); bool response_buf_full(); - void add_response_sent_bodylen(size_t amount); - int64_t get_response_sent_bodylen() const; // Validates that received response body length and content-length // matches. bool validate_response_recv_body_length() const; @@ -381,6 +379,9 @@ public: Downstream *dlnext, *dlprev; + // the length of response body sent to upstream client + int64_t response_sent_body_length; + private: Request req_; Response resp_; @@ -401,9 +402,6 @@ private: ev_timer downstream_rtimer_; ev_timer downstream_wtimer_; - // the length of response body sent to upstream client - int64_t response_sent_bodylen_; - Upstream *upstream_; std::unique_ptr dconn_; diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index ac719484..f02a3868 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -728,9 +728,7 @@ int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, // We have to add length here, so that we can log this amount of // data transferred. - if (length > 0) { - downstream->add_response_sent_bodylen(length); - } + downstream->response_sent_body_length += length; return (nwrite < length || npadwrite < padlen) ? NGHTTP2_ERR_PAUSE : 0; } diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index b2e11e67..b364608f 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -799,7 +799,7 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body, output->append(body, bodylen); - downstream->add_response_sent_bodylen(bodylen); + downstream->response_sent_body_length += bodylen; downstream->set_response_state(Downstream::MSG_COMPLETE); return 0; @@ -842,7 +842,7 @@ void HttpsUpstream::error_reply(unsigned int status_code) { "charset=UTF-8\r\nConnection: close\r\n\r\n"); output->append(html.c_str(), html.size()); - downstream->add_response_sent_bodylen(html.size()); + downstream->response_sent_body_length += html.size(); downstream->set_response_state(Downstream::MSG_COMPLETE); } @@ -1048,7 +1048,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream, } output->append(data, len); - downstream->add_response_sent_bodylen(len); + downstream->response_sent_body_length += len; if (downstream->get_chunked_response()) { output->append("\r\n"); diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index e29dca1c..629d5d12 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -804,7 +804,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session, int32_t stream_id, } if (nread > 0) { - downstream->add_response_sent_bodylen(nread); + downstream->response_sent_body_length += nread; } return nread;