From c06affed2ac5a73cb1ebae2a5ef8750cc7370f3f Mon Sep 17 00:00:00 2001 From: antao Date: Fri, 1 Mar 2019 18:12:20 +0800 Subject: [PATCH] Update the submodule trantor --- lib/inc/drogon/HttpViewData.h | 2 +- lib/src/HttpRequestImpl.cc | 4 ++-- lib/src/HttpResponseImpl.cc | 15 +++++++-------- trantor | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/inc/drogon/HttpViewData.h b/lib/inc/drogon/HttpViewData.h index 9467d642..fa58ffc5 100755 --- a/lib/inc/drogon/HttpViewData.h +++ b/lib/inc/drogon/HttpViewData.h @@ -74,7 +74,7 @@ class HttpViewData const char *format, ...) { std::string strBuffer; - strBuffer.resize(1024); + strBuffer.resize(128); va_list ap, backup_ap; va_start(ap, format); va_copy(backup_ap, ap); diff --git a/lib/src/HttpRequestImpl.cc b/lib/src/HttpRequestImpl.cc index ee30afb9..8d11d3e1 100755 --- a/lib/src/HttpRequestImpl.cc +++ b/lib/src/HttpRequestImpl.cc @@ -219,8 +219,8 @@ void HttpRequestImpl::appendToBuffer(MsgBuffer *output) const if (!content.empty() || !_content.empty()) { char buf[64]; - snprintf(buf, sizeof buf, "Content-Length: %lu\r\n", static_cast(content.length() + _content.length())); - output->append(buf); + auto len = snprintf(buf, sizeof(buf), "Content-Length: %lu\r\n", static_cast(content.length() + _content.length())); + output->append(buf, len); if (_contentTypeString.empty()) { auto &type = webContentTypeToString(_contentType); diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index 39b6598c..5ba59274 100755 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -291,16 +291,16 @@ const char *HttpResponseImpl::statusCodeToString(int code) } void HttpResponseImpl::makeHeaderString(const std::shared_ptr &headerStringPtr) const { - char buf[64]; + char buf[128]; assert(headerStringPtr); - snprintf(buf, sizeof buf, "HTTP/1.1 %d ", _statusCode); - headerStringPtr->append(buf); + auto len = snprintf(buf, sizeof buf, "HTTP/1.1 %d ", _statusCode); + headerStringPtr->append(buf, len); if (_statusMessage) headerStringPtr->append(_statusMessage); headerStringPtr->append("\r\n"); if (_sendfileName.empty()) { - snprintf(buf, sizeof buf, "Content-Length: %lu\r\n", static_cast(_bodyPtr->size())); + len = snprintf(buf, sizeof buf, "Content-Length: %lu\r\n", static_cast(_bodyPtr->size())); } else { @@ -310,10 +310,10 @@ void HttpResponseImpl::makeHeaderString(const std::shared_ptr &head LOG_SYSERR << _sendfileName << " stat error"; return; } - snprintf(buf, sizeof buf, "Content-Length: %llu\r\n", static_cast(filestat.st_size)); + len = snprintf(buf, sizeof buf, "Content-Length: %llu\r\n", static_cast(filestat.st_size)); } - headerStringPtr->append(buf); + headerStringPtr->append(buf, len); if (_headers.find("Connection") == _headers.end()) { if (_closeConnection) @@ -359,8 +359,7 @@ std::shared_ptr HttpResponseImpl::renderToString() const return _httpString; } } - auto httpString = std::make_shared(); - httpString->reserve(256); + auto httpString = std::make_shared(256, '\0'); if (!_fullHeaderString) { makeHeaderString(httpString); diff --git a/trantor b/trantor index 35163a32..52d757bb 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 35163a32c428d34d5783840d46972ecc42f8268e +Subproject commit 52d757bbc85ac7f6c4118b9b675813e92cb8e8e0