nghttpx: Refactor Downstream::response_sent_bodylen_

This commit is contained in:
Tatsuhiro Tsujikawa 2016-01-14 23:54:28 +09:00
parent 3218c160be
commit 5a8cf94361
6 changed files with 13 additions and 25 deletions

View File

@ -834,7 +834,7 @@ void ClientHandler::write_accesslog(Downstream *downstream) {
std::chrono::high_resolution_clock::now(), // request_end_time std::chrono::high_resolution_clock::now(), // request_end_time
req.http_major, req.http_minor, resp.http_status, 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, get_config()->port, get_config()->pid,
}); });
} }

View File

@ -113,11 +113,11 @@ void downstream_wtimeoutcb(struct ev_loop *loop, ev_timer *w, int revents) {
// upstream could be nullptr for unittests // upstream could be nullptr for unittests
Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool,
int32_t stream_id, int32_t priority) 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_start_time_(std::chrono::high_resolution_clock::now()),
request_buf_(mcpool), response_buf_(mcpool), response_sent_bodylen_(0), request_buf_(mcpool), response_buf_(mcpool), upstream_(upstream),
upstream_(upstream), blocked_link_(nullptr), num_retry_(0), blocked_link_(nullptr), num_retry_(0), stream_id_(stream_id),
stream_id_(stream_id), priority_(priority), downstream_stream_id_(-1), priority_(priority), downstream_stream_id_(-1),
response_rst_stream_error_code_(NGHTTP2_NO_ERROR), response_rst_stream_error_code_(NGHTTP2_NO_ERROR),
request_state_(INITIAL), response_state_(INITIAL), request_state_(INITIAL), response_state_(INITIAL),
dispatch_state_(DISPATCH_NONE), upgraded_(false), chunked_request_(false), 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 { bool Downstream::validate_request_recv_body_length() const {
if (req_.fs.content_length == -1) { if (req_.fs.content_length == -1) {
return true; return true;

View File

@ -297,8 +297,6 @@ public:
int get_response_state() const; int get_response_state() const;
DefaultMemchunks *get_response_buf(); DefaultMemchunks *get_response_buf();
bool response_buf_full(); 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 // Validates that received response body length and content-length
// matches. // matches.
bool validate_response_recv_body_length() const; bool validate_response_recv_body_length() const;
@ -381,6 +379,9 @@ public:
Downstream *dlnext, *dlprev; Downstream *dlnext, *dlprev;
// the length of response body sent to upstream client
int64_t response_sent_body_length;
private: private:
Request req_; Request req_;
Response resp_; Response resp_;
@ -401,9 +402,6 @@ private:
ev_timer downstream_rtimer_; ev_timer downstream_rtimer_;
ev_timer downstream_wtimer_; ev_timer downstream_wtimer_;
// the length of response body sent to upstream client
int64_t response_sent_bodylen_;
Upstream *upstream_; Upstream *upstream_;
std::unique_ptr<DownstreamConnection> dconn_; std::unique_ptr<DownstreamConnection> dconn_;

View File

@ -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 // We have to add length here, so that we can log this amount of
// data transferred. // data transferred.
if (length > 0) { downstream->response_sent_body_length += length;
downstream->add_response_sent_bodylen(length);
}
return (nwrite < length || npadwrite < padlen) ? NGHTTP2_ERR_PAUSE : 0; return (nwrite < length || npadwrite < padlen) ? NGHTTP2_ERR_PAUSE : 0;
} }

View File

@ -799,7 +799,7 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body,
output->append(body, bodylen); output->append(body, bodylen);
downstream->add_response_sent_bodylen(bodylen); downstream->response_sent_body_length += bodylen;
downstream->set_response_state(Downstream::MSG_COMPLETE); downstream->set_response_state(Downstream::MSG_COMPLETE);
return 0; return 0;
@ -842,7 +842,7 @@ void HttpsUpstream::error_reply(unsigned int status_code) {
"charset=UTF-8\r\nConnection: close\r\n\r\n"); "charset=UTF-8\r\nConnection: close\r\n\r\n");
output->append(html.c_str(), html.size()); 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); downstream->set_response_state(Downstream::MSG_COMPLETE);
} }
@ -1048,7 +1048,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
} }
output->append(data, len); output->append(data, len);
downstream->add_response_sent_bodylen(len); downstream->response_sent_body_length += len;
if (downstream->get_chunked_response()) { if (downstream->get_chunked_response()) {
output->append("\r\n"); output->append("\r\n");

View File

@ -804,7 +804,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session, int32_t stream_id,
} }
if (nread > 0) { if (nread > 0) {
downstream->add_response_sent_bodylen(nread); downstream->response_sent_body_length += nread;
} }
return nread; return nread;