diff --git a/drogon_ctl/create_model.cc b/drogon_ctl/create_model.cc index 1c4c1bb9..58b6ead1 100644 --- a/drogon_ctl/create_model.cc +++ b/drogon_ctl/create_model.cc @@ -42,6 +42,10 @@ std::string nameTransform(const std::string &origName, bool isType) do { pos = str.find("_", startPos); + if (pos == std::string::npos) + { + pos = str.find(".", startPos); + } if (pos != std::string::npos) ret += str.substr(startPos, pos - startPos); else @@ -49,7 +53,7 @@ std::string nameTransform(const std::string &origName, bool isType) ret += str.substr(startPos); break; } - while (str[pos] == '_') + while (str[pos] == '_' || str[pos] == '.') pos++; if (str[pos] >= 'a' && str[pos] <= 'z') str[pos] += ('A' - 'a'); diff --git a/lib/src/HttpRequestImpl.cc b/lib/src/HttpRequestImpl.cc index d75f3abd..ab00f5cd 100644 --- a/lib/src/HttpRequestImpl.cc +++ b/lib/src/HttpRequestImpl.cc @@ -309,7 +309,7 @@ void HttpRequestImpl::addHeader(const char *start, { value.resize(value.size() - 1); } - if (field == "cookie") + if (field.length() == 6 && field == "cookie") { LOG_TRACE << "cookies!!!:" << value; std::string::size_type pos; @@ -349,13 +349,39 @@ void HttpRequestImpl::addHeader(const char *start, } else { - if (field == "content-length") + switch (field.length()) { - _contentLen = std::stoull(value.c_str()); - } - else if (field == "expect") - { - _expect = value; + case 6: + if (field == "expect") + { + _expect = value; + } + break; + case 10: + { + if (field == "connection") + { + if (_version == kHttp11) + { + if (value.length() == 5 && value == "close") + _keepAlive = false; + } + else if (value.length() == 10 && + (value == "Keep-Alive" || value == "keep-alive")) + { + _keepAlive = true; + } + } + } + break; + case 14: + if (field == "content-length") + { + _contentLen = std::stoull(value.c_str()); + } + break; + default: + break; } _headers.emplace(std::move(field), std::move(value)); } diff --git a/lib/src/HttpRequestImpl.h b/lib/src/HttpRequestImpl.h index af3e4b13..9ff397d7 100644 --- a/lib/src/HttpRequestImpl.h +++ b/lib/src/HttpRequestImpl.h @@ -65,6 +65,7 @@ class HttpRequestImpl : public HttpRequest _content.clear(); _contentType = CT_TEXT_PLAIN; _contentTypeString.clear(); + _keepAlive = true; } trantor::EventLoop *getLoop() { @@ -74,6 +75,10 @@ class HttpRequestImpl : public HttpRequest void setVersion(Version v) { _version = v; + if (v == kHttp10) + { + _keepAlive = false; + } } virtual Version version() const override @@ -378,6 +383,10 @@ class HttpRequestImpl : public HttpRequest { return _expect; } + bool keepAlive() const + { + return _keepAlive; + } ~HttpRequestImpl(); protected: @@ -419,6 +428,7 @@ class HttpRequestImpl : public HttpRequest trantor::Date _date; std::unique_ptr _cacheFilePtr; std::string _expect; + bool _keepAlive = true; protected: std::string _content; diff --git a/lib/src/HttpServer.cc b/lib/src/HttpServer.cc index b8bf9f1f..0b9f1c9a 100644 --- a/lib/src/HttpServer.cc +++ b/lib/src/HttpServer.cc @@ -271,11 +271,7 @@ void HttpServer::onRequests( for (auto &req : requests) { - const std::string &connection = req->getHeaderBy("connection"); - bool _close = connection == "close" || - (req->getVersion() == HttpRequestImpl::kHttp10 && - connection != "Keep-Alive"); - + bool _close = (!req->keepAlive()); bool isHeadMethod = (req->method() == Head); if (isHeadMethod) {