From b2c9db7eb0f7e034316458d648562aab9d2f8dcb Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Thu, 21 Jun 2018 15:39:11 +0800 Subject: [PATCH] modify val names --- lib/src/HttpContext.cc | 38 ++++++++--------- lib/src/HttpResponseImpl.cc | 18 ++++---- lib/src/HttpResponseImpl.h | 82 ++++++++++++++++++------------------- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/lib/src/HttpContext.cc b/lib/src/HttpContext.cc index fff46b3f..b0a526cc 100755 --- a/lib/src/HttpContext.cc +++ b/lib/src/HttpContext.cc @@ -277,7 +277,7 @@ bool HttpContext::parseResponse(MsgBuffer *buf) LOG_INFO << "content len=" << len; if (len != "") { - response_.left_body_length_ = atoi(len.c_str()); + response_._left_body_length = atoi(len.c_str()); res_state_ = HttpResponseParseState::kExpectBody; } else @@ -308,28 +308,28 @@ bool HttpContext::parseResponse(MsgBuffer *buf) //LOG_INFO << "expectBody:buf=" << buf; if (buf->readableBytes() == 0) { - if (response_.left_body_length_ == 0) + if (response_._left_body_length == 0) { res_state_ = HttpResponseParseState::kGotAll; } break; } - if (response_.left_body_length_ >= buf->readableBytes()) + if (response_._left_body_length >= buf->readableBytes()) { - response_.left_body_length_ -= buf->readableBytes(); - response_.body_ += std::string(buf->peek(), buf->readableBytes()); + response_._left_body_length -= buf->readableBytes(); + response_._body += std::string(buf->peek(), buf->readableBytes()); buf->retrieveAll(); } else { - response_.body_ += std::string(buf->peek(), response_.left_body_length_); + response_._body += std::string(buf->peek(), response_._left_body_length); buf->retrieve(request_.contentLen); - response_.left_body_length_ = 0; + response_._left_body_length = 0; } - if (response_.left_body_length_ == 0) + if (response_._left_body_length == 0) { res_state_ = HttpResponseParseState::kGotAll; - LOG_TRACE << "post got all:len=" << response_.left_body_length_; + LOG_TRACE << "post got all:len=" << response_._left_body_length; //LOG_INFO<<"content:"<peek(), buf->readableBytes()); + response_._body += std::string(buf->peek(), buf->readableBytes()); buf->retrieveAll(); break; } @@ -349,9 +349,9 @@ bool HttpContext::parseResponse(MsgBuffer *buf) //chunk length line std::string len(buf->peek(), crlf - buf->peek()); char *end; - response_.current_chunk_length_ = strtol(len.c_str(), &end, 16); - LOG_TRACE << "chun length : " << response_.current_chunk_length_; - if (response_.current_chunk_length_ != 0) + response_._current_chunk_length = strtol(len.c_str(), &end, 16); + LOG_TRACE << "chun length : " << response_._current_chunk_length; + if (response_._current_chunk_length != 0) { res_state_ = HttpResponseParseState::kExpectChunkBody; } @@ -371,20 +371,20 @@ bool HttpContext::parseResponse(MsgBuffer *buf) const char *crlf = buf->findCRLF(); if (crlf) { - if (response_.current_chunk_length_ == (size_t)(crlf - buf->peek())) + if (response_._current_chunk_length == (size_t)(crlf - buf->peek())) { //current chunk end crlf - response_.body_ += std::string(buf->peek(), response_.current_chunk_length_); + response_._body += std::string(buf->peek(), response_._current_chunk_length); buf->retrieveUntil(crlf + 2); - response_.current_chunk_length_ = 0; + response_._current_chunk_length = 0; res_state_ = HttpResponseParseState::kExpectChunkLen; } - else if (response_.current_chunk_length_ > (size_t)(crlf - buf->peek())) + else if (response_._current_chunk_length > (size_t)(crlf - buf->peek())) { //current chunk body crlf - response_.body_ += std::string(buf->peek(), crlf - buf->peek() + 1); + response_._body += std::string(buf->peek(), crlf - buf->peek() + 1); buf->retrieveUntil(crlf + 2); - response_.current_chunk_length_ -= (crlf - buf->peek() + 2); + response_._current_chunk_length -= (crlf - buf->peek() + 2); } } else diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index fea125d0..4d8c7eec 100755 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -187,29 +187,29 @@ const std::string HttpResponseImpl::web_response_code_to_string(int code) void HttpResponseImpl::appendToBuffer(MsgBuffer* output) const { char buf[32]; - snprintf(buf, sizeof buf, "HTTP/1.1 %d ", statusCode_); + snprintf(buf, sizeof buf, "HTTP/1.1 %d ", _statusCode); output->append(buf); - output->append(statusMessage_); + output->append(_statusMessage); output->append("\r\n"); - snprintf(buf, sizeof buf, "Content-Length: %lu\r\n", body_.size()); + snprintf(buf, sizeof buf, "Content-Length: %lu\r\n", _body.size()); output->append(buf); - if (closeConnection_) { + if (_closeConnection) { output->append("Connection: close\r\n"); } else { output->append("Connection: Keep-Alive\r\n"); } - for (std::map::const_iterator it = headers_.begin(); - it != headers_.end(); + for (auto it = _headers.begin(); + it != _headers.end(); ++it) { output->append(it->first); output->append(": "); output->append(it->second); output->append("\r\n"); } - if(cookies_.size() > 0) { - for(auto it = cookies_.begin(); it != cookies_.end(); it++) { + if(_cookies.size() > 0) { + for(auto it = _cookies.begin(); it != _cookies.end(); it++) { output->append(it->second.cookieString()); } @@ -218,6 +218,6 @@ void HttpResponseImpl::appendToBuffer(MsgBuffer* output) const output->append("\r\n"); LOG_TRACE<<"reponse(no body):"<peek(); - output->append(body_); + output->append(_body); } diff --git a/lib/src/HttpResponseImpl.h b/lib/src/HttpResponseImpl.h index 964cdd62..67b316a9 100755 --- a/lib/src/HttpResponseImpl.h +++ b/lib/src/HttpResponseImpl.h @@ -66,62 +66,62 @@ namespace drogon public: explicit HttpResponseImpl() - : statusCode_(kUnknown), - closeConnection_(false), - left_body_length_(0), - current_chunk_length_(0) + : _statusCode(kUnknown), + _closeConnection(false), + _left_body_length(0), + _current_chunk_length(0) { } virtual void setStatusCode(HttpStatusCode code) override { - statusCode_ = code; + _statusCode = code; setStatusMessage(web_response_code_to_string(code)); } virtual void setStatusCode(HttpStatusCode code, const std::string& status_message) override { - statusCode_ = code; + _statusCode = code; setStatusMessage(status_message); } virtual void setVersion(const Version v) override { - v_ = v; + _v = v; } virtual void setCloseConnection(bool on) override { - closeConnection_ = on; + _closeConnection = on; } virtual bool closeConnection() const override { - return closeConnection_; + return _closeConnection; } virtual void setContentTypeCode(uint8_t type) override { - contentType_=type; + _contentType=type; setContentType(web_content_type_to_string(type)); } virtual std::string getHeader(const std::string& key) override { - if(headers_.find(key) == headers_.end()) + if(_headers.find(key) == _headers.end()) { return ""; } else { - return headers_[key]; + return _headers[key]; } } virtual void addHeader(const std::string& key, const std::string& value) override { - headers_[key] = value; + _headers[key] = value; } virtual void addHeader(const char* start, const char* colon, const char* end) override @@ -135,7 +135,7 @@ namespace drogon while (!value.empty() && isspace(value[value.size() - 1])) { value.resize(value.size() - 1); } - headers_[field] = value; + _headers[field] = value; transform(field.begin(), field.end(), field.begin(), ::tolower); if(field == "cookie") { //LOG_INFO<<"cookies!!!:"< headers_; - std::map cookies_; - HttpStatusCode statusCode_; + std::map _headers; + std::map _cookies; + HttpStatusCode _statusCode; // FIXME: add http version - Version v_; - std::string statusMessage_; - bool closeConnection_; - std::string body_; - size_t left_body_length_; - size_t current_chunk_length_; - uint8_t contentType_=CT_TEXT_HTML; + Version _v; + std::string _statusMessage; + bool _closeConnection; + std::string _body; + size_t _left_body_length; + size_t _current_chunk_length; + uint8_t _contentType=CT_TEXT_HTML; //trantor::Date receiveTime_; void setContentType(const std::string& contentType) @@ -241,7 +241,7 @@ namespace drogon } void setStatusMessage(const std::string& message) { - statusMessage_ = message; + _statusMessage = message; } };