Merge branch 'v1.3.0' into connection_monitor

This commit is contained in:
lganzzzo 2021-09-15 00:27:10 +03:00
commit ee03d7bc54
13 changed files with 163 additions and 10 deletions

View File

@ -180,6 +180,46 @@ public:
}
/**
* Erases all occurrences of key and replaces them with a new entry
* @param key
* @param value
* @return - true if an entry was replaced, false if entry was only inserted.
*/
bool putOrReplace(const Key& key, const StringKeyLabel& value) {
std::lock_guard<concurrency::SpinLock> lock(m_lock);
bool needsErase = m_map.find(key) != m_map.end();
if (needsErase) {
m_map.erase(key);
}
m_map.insert({key, value});
m_fullyInitialized = false;
return needsErase;
}
/**
* Erases all occurrences of key and replaces them with a new entry. Not thread-safe.
* @param key
* @param value
* @return - `true` if an entry was replaced, `false` if entry was only inserted.
*/
bool putOrReplace_LockFree(const Key& key, const StringKeyLabel& value) {
bool needsErase = m_map.find(key) != m_map.end();
if (needsErase) {
m_map.erase(key);
}
m_map.insert({key, value});
m_fullyInitialized = false;
return needsErase;
}
/**
* Get value as &id:oatpp::String;.
* @param key

View File

@ -39,7 +39,7 @@ std::shared_ptr<QueryResult> Executor::execute(const oatpp::String& query,
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver,
const std::shared_ptr<Connection>& connection)
{
const auto& qt = parseQueryTemplate(nullptr, query, {}, false);
const auto& qt = parseQueryTemplate(nullptr, query, ParamsTypeMap(), false);
return execute(qt, params, typeResolver, connection);
}

View File

@ -101,6 +101,15 @@ bool Request::putHeaderIfNotExists(const oatpp::String& key, const oatpp::String
return m_headers.putIfNotExists(key, value);
}
bool Request::putOrReplaceHeader(const String &key, const String &value) {
return m_headers.putOrReplace(key, value);
}
bool Request::putOrReplaceHeader_Unsafe(const data::share::StringKeyLabelCI& key,
const data::share::StringKeyLabel &value) {
return m_headers.putOrReplace(key, value);
}
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}

View File

@ -154,6 +154,22 @@ public:
*/
bool putHeaderIfNotExists(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::String;.
* @param value - &id:oatpp::String;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.

View File

@ -66,6 +66,15 @@ bool Response::putHeaderIfNotExists(const oatpp::String& key, const oatpp::Strin
return m_headers.putIfNotExists(key, value);
}
bool Response::putOrReplaceHeader(const String &key, const String &value) {
return m_headers.putOrReplace(key, value);
}
bool Response::putOrReplaceHeader_Unsafe(const data::share::StringKeyLabelCI& key,
const data::share::StringKeyLabel &value) {
return m_headers.putOrReplace(key, value);
}
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}

View File

@ -116,6 +116,22 @@ public:
*/
bool putHeaderIfNotExists(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::String;.
* @param value - &id:oatpp::String;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.

View File

@ -26,23 +26,24 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace outgoing {
BufferBody::BufferBody(const oatpp::String& buffer, const data::share::StringKeyLabel& contentType)
BufferBody::BufferBody(const oatpp::String &buffer, const data::share::StringKeyLabel &contentType)
: m_buffer(buffer)
, m_contentType(contentType)
, m_inlineData((void*) m_buffer->data(), m_buffer->size())
{}
std::shared_ptr<BufferBody> BufferBody::createShared(const oatpp::String& buffer, const data::share::StringKeyLabel& contentType) {
std::shared_ptr<BufferBody> BufferBody::createShared(const oatpp::String &buffer,
const data::share::StringKeyLabel &contentType) {
return Shared_Http_Outgoing_BufferBody_Pool::allocateShared(buffer, contentType);
}
v_io_size BufferBody::read(void *buffer, v_buff_size count, async::Action& action) {
v_io_size BufferBody::read(void *buffer, v_buff_size count, async::Action &action) {
(void) action;
v_buff_size desiredToRead = m_inlineData.bytesLeft;
if(desiredToRead > 0) {
if (desiredToRead > 0) {
if (desiredToRead > count) {
desiredToRead = count;
@ -59,9 +60,9 @@ v_io_size BufferBody::read(void *buffer, v_buff_size count, async::Action& actio
}
void BufferBody::declareHeaders(Headers& headers) {
if(m_contentType) {
headers.put(Header::CONTENT_TYPE, m_contentType);
void BufferBody::declareHeaders(Headers &headers) {
if (m_contentType) {
headers.putIfNotExists(Header::CONTENT_TYPE, m_contentType);
}
}

View File

@ -68,6 +68,15 @@ bool Request::putHeaderIfNotExists(const oatpp::String& key, const oatpp::String
return m_headers.putIfNotExists(key, value);
}
bool Request::putOrReplaceHeader(const String &key, const String &value) {
return m_headers.putOrReplace(key, value);
}
bool Request::putOrReplaceHeader_Unsafe(const data::share::StringKeyLabelCI& key,
const data::share::StringKeyLabel &value) {
return m_headers.putOrReplace(key, value);
}
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}

View File

@ -109,6 +109,22 @@ public:
*/
bool putHeaderIfNotExists(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::String;.
* @param value - &id:oatpp::String;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.

View File

@ -60,6 +60,15 @@ bool Response::putHeaderIfNotExists(const oatpp::String& key, const oatpp::Strin
return m_headers.putIfNotExists(key, value);
}
bool Response::putOrReplaceHeader(const String &key, const String &value) {
return m_headers.putOrReplace(key, value);
}
bool Response::putOrReplaceHeader_Unsafe(const data::share::StringKeyLabelCI& key,
const data::share::StringKeyLabel &value) {
return m_headers.putOrReplace(key, value);
}
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}

View File

@ -110,6 +110,22 @@ public:
*/
bool putHeaderIfNotExists(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::String;.
* @param value - &id:oatpp::String;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader(const oatpp::String& key, const oatpp::String& value);
/**
* Replaces or adds header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was replaces, `false` if header was added.
*/
bool putOrReplaceHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.

View File

@ -483,6 +483,12 @@ void FullTest::onRun() {
OATPP_ASSERT(value == "Hello World!!!");
}
{ // test header replacement
auto response = client->getInterceptors(connection);
OATPP_ASSERT(response->getStatusCode() == 200);
OATPP_ASSERT(response->getHeader("to-be-replaced") == "replaced_value");
}
if((i + 1) % iterationsStep == 0) {
auto ticks = oatpp::base::Environment::getMicroTickCount() - lastTick;
lastTick = oatpp::base::Environment::getMicroTickCount();

View File

@ -83,6 +83,11 @@ public:
response->putHeader("header-out-inter3", "inter3");
return response;
}
ENDPOINT_INTERCEPTOR(interceptor, replacer) {
auto response = (this->*intercepted)(request);
response->putOrReplaceHeader("to-be-replaced", "replaced_value");
return response;
}
ENDPOINT_INTERCEPTOR(interceptor, asserter) {
auto response = (this->*intercepted)(request);
@ -100,8 +105,9 @@ public:
OATPP_ASSERT(request->getHeader("header-in-inter2") == "inter2");
OATPP_ASSERT(request->getHeader("header-in-inter3") == "inter3");
return createResponse(Status::CODE_200, "Hello World!!!");
auto response = createResponse(Status::CODE_200, "Hello World!!!");
response->putHeader("to-be-replaced", "original_value");
return response;
}