mirror of https://github.com/CrowCpp/Crow.git
Compare commits
3 Commits
5895a9cd2c
...
d4a641b072
Author | SHA1 | Date |
---|---|---|
gittiver | d4a641b072 | |
Gulliver | fb370ab7b6 | |
AndreyTokmakov | 1b6a4f4301 |
|
@ -24,8 +24,8 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-latest,
|
os: [ ubuntu-latest,
|
||||||
windows-latest,
|
windows-latest,
|
||||||
ubuntu-20.04,
|
|
||||||
macos-latest,
|
macos-latest,
|
||||||
|
ubuntu-20.04,
|
||||||
macos-11
|
macos-11
|
||||||
]
|
]
|
||||||
# ubuntu-18.04 does not work due to compile error on asio
|
# ubuntu-18.04 does not work due to compile error on asio
|
||||||
|
@ -55,7 +55,8 @@ jobs:
|
||||||
if [ "$RUNNER_OS" == "Windows" ]; then
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
||||||
cmake \
|
cmake \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
|
||||||
-DCROW_FEATURES="ssl;compression" \
|
-DCROW_ENABLE_SSL=ON \
|
||||||
|
-DCROW_ENABLE_COMPRESSION=ON \
|
||||||
-DCROW_AMALGAMATE=ON \
|
-DCROW_AMALGAMATE=ON \
|
||||||
-DCROW_BUILD_TESTS=ON \
|
-DCROW_BUILD_TESTS=ON \
|
||||||
-B build
|
-B build
|
||||||
|
@ -63,13 +64,15 @@ jobs:
|
||||||
LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" \
|
LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" \
|
||||||
CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" \
|
CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" \
|
||||||
cmake \
|
cmake \
|
||||||
-DCROW_FEATURES="ssl;compression" \
|
-DCROW_ENABLE_SSL=ON \
|
||||||
|
-DCROW_ENABLE_COMPRESSION=ON \
|
||||||
-DCROW_AMALGAMATE=ON \
|
-DCROW_AMALGAMATE=ON \
|
||||||
-DCROW_BUILD_TESTS=ON \
|
-DCROW_BUILD_TESTS=ON \
|
||||||
-B build
|
-B build
|
||||||
else
|
else
|
||||||
cmake \
|
cmake \
|
||||||
-DCROW_FEATURES="ssl;compression" \
|
-DCROW_ENABLE_SSL=ON \
|
||||||
|
-DCROW_ENABLE_COMPRESSION=ON \
|
||||||
-DCROW_AMALGAMATE=ON \
|
-DCROW_AMALGAMATE=ON \
|
||||||
-DCROW_BUILD_TESTS=ON \
|
-DCROW_BUILD_TESTS=ON \
|
||||||
-B build
|
-B build
|
||||||
|
|
|
@ -49,7 +49,10 @@ option(CROW_INSTALL "Add install step for Crow" ON )
|
||||||
option(CROW_USE_BOOST "Use Boost.Asio for Crow" OFF)
|
option(CROW_USE_BOOST "Use Boost.Asio for Crow" OFF)
|
||||||
|
|
||||||
# Possible values: ssl, compression
|
# Possible values: ssl, compression
|
||||||
option(CROW_FEATURES "Enable features extending Crow's abilities" "")
|
#option(CROW_FEATURES "Enable features extending Crow's abilities" "")
|
||||||
|
option(CROW_ENABLE_SSL "Enable Crow's SSL feature" OFF)
|
||||||
|
option(CROW_ENABLE_COMPRESSION "Enable Crow's Compression feature" OFF)
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# Define Targets
|
# Define Targets
|
||||||
|
@ -80,13 +83,13 @@ endif()
|
||||||
|
|
||||||
target_compile_definitions(Crow INTERFACE "")
|
target_compile_definitions(Crow INTERFACE "")
|
||||||
|
|
||||||
if("compression" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_COMPRESSION)
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
target_link_libraries(Crow INTERFACE ZLIB::ZLIB)
|
target_link_libraries(Crow INTERFACE ZLIB::ZLIB)
|
||||||
target_compile_definitions(Crow INTERFACE CROW_ENABLE_COMPRESSION)
|
target_compile_definitions(Crow INTERFACE CROW_ENABLE_COMPRESSION)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("ssl" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_SSL)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
target_link_libraries(Crow INTERFACE OpenSSL::SSL)
|
target_link_libraries(Crow INTERFACE OpenSSL::SSL)
|
||||||
target_compile_definitions(Crow INTERFACE CROW_ENABLE_SSL)
|
target_compile_definitions(Crow INTERFACE CROW_ENABLE_SSL)
|
||||||
|
@ -119,11 +122,11 @@ if(CROW_BUILD_TESTS)
|
||||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest
|
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT "compression" IN_LIST CROW_FEATURES)
|
if(NOT CROW_ENABLE_COMPRESSION)
|
||||||
message(STATUS "Compression tests are omitted. (Configure with CROW_FEATURES containing 'compression' to enable them)")
|
message(STATUS "Compression tests are omitted. (Configure with CROW_ENABLE_COMPRESSION to enable them)")
|
||||||
endif()
|
endif()
|
||||||
if(NOT "ssl" IN_LIST CROW_FEATURES)
|
if(NOT CROW_ENABLE_SSL)
|
||||||
message(STATUS "SSL tests are omitted. (Configure with CROW_FEATURES containing 'ssl' to enable them)")
|
message(STATUS "SSL tests are omitted. (Configure with CROW_ENABLE_SSL to enable them)")
|
||||||
else()
|
else()
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -14,11 +14,11 @@ if(NOT DEFINED CROW_FEATURES)
|
||||||
set(CROW_FEATURES ${CROW_INSTALLED_FEATURES})
|
set(CROW_FEATURES ${CROW_INSTALLED_FEATURES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("compression" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_COMPRESSION)
|
||||||
find_dependency(ZLIB)
|
find_dependency(ZLIB)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("ssl" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_SSL)
|
||||||
find_dependency(OpenSSL)
|
find_dependency(OpenSSL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ endif()
|
||||||
list(REMOVE_ITEM _CROW_ILL "ZLIB::ZLIB" "OpenSSL::SSL")
|
list(REMOVE_ITEM _CROW_ILL "ZLIB::ZLIB" "OpenSSL::SSL")
|
||||||
list(REMOVE_ITEM _CROW_ICD "CROW_ENABLE_SSL" "CROW_ENABLE_COMPRESSION")
|
list(REMOVE_ITEM _CROW_ICD "CROW_ENABLE_SSL" "CROW_ENABLE_COMPRESSION")
|
||||||
|
|
||||||
if("compression" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_COMPRESSION)
|
||||||
list(APPEND _CROW_ILL "ZLIB::ZLIB")
|
list(APPEND _CROW_ILL "ZLIB::ZLIB")
|
||||||
list(APPEND _CROW_ICD "CROW_ENABLE_COMPRESSION")
|
list(APPEND _CROW_ICD "CROW_ENABLE_COMPRESSION")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("ssl" IN_LIST CROW_FEATURES)
|
if(CROW_ENABLE_SSL)
|
||||||
list(APPEND _CROW_ILL "OpenSSL::SSL")
|
list(APPEND _CROW_ILL "OpenSSL::SSL")
|
||||||
list(APPEND _CROW_ICD "CROW_ENABLE_SSL")
|
list(APPEND _CROW_ICD "CROW_ENABLE_SSL")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -138,7 +138,7 @@ inline size_t qs_parse(char* qs, char* qs_kv[], size_t qs_kv_size, bool parse_ur
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int qs_decode(char * qs)
|
inline int qs_decode(char * qs)
|
||||||
|
@ -295,9 +295,7 @@ namespace crow
|
||||||
public:
|
public:
|
||||||
static const int MAX_KEY_VALUE_PAIRS_COUNT = 256;
|
static const int MAX_KEY_VALUE_PAIRS_COUNT = 256;
|
||||||
|
|
||||||
query_string()
|
query_string() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
query_string(const query_string& qs):
|
query_string(const query_string& qs):
|
||||||
url_(qs.url_)
|
url_(qs.url_)
|
||||||
|
@ -319,7 +317,7 @@ namespace crow
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
query_string& operator=(query_string&& qs)
|
query_string& operator=(query_string&& qs) noexcept
|
||||||
{
|
{
|
||||||
key_value_pairs_ = std::move(qs.key_value_pairs_);
|
key_value_pairs_ = std::move(qs.key_value_pairs_);
|
||||||
char* old_data = (char*)qs.url_.c_str();
|
char* old_data = (char*)qs.url_.c_str();
|
||||||
|
@ -339,9 +337,10 @@ namespace crow
|
||||||
return;
|
return;
|
||||||
|
|
||||||
key_value_pairs_.resize(MAX_KEY_VALUE_PAIRS_COUNT);
|
key_value_pairs_.resize(MAX_KEY_VALUE_PAIRS_COUNT);
|
||||||
|
|
||||||
size_t count = qs_parse(&url_[0], &key_value_pairs_[0], MAX_KEY_VALUE_PAIRS_COUNT, url);
|
size_t count = qs_parse(&url_[0], &key_value_pairs_[0], MAX_KEY_VALUE_PAIRS_COUNT, url);
|
||||||
|
|
||||||
key_value_pairs_.resize(count);
|
key_value_pairs_.resize(count);
|
||||||
|
key_value_pairs_.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
|
@ -472,13 +471,19 @@ namespace crow
|
||||||
|
|
||||||
std::vector<std::string> keys() const
|
std::vector<std::string> keys() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> keys;
|
||||||
for (auto element : key_value_pairs_)
|
keys.reserve(key_value_pairs_.size());
|
||||||
|
|
||||||
|
for (const char* const element : key_value_pairs_)
|
||||||
{
|
{
|
||||||
std::string str_element(element);
|
const char* delimiter = strchr(element, '=');
|
||||||
ret.emplace_back(str_element.substr(0, str_element.find('=')));
|
if (delimiter)
|
||||||
|
keys.emplace_back(element, delimiter);
|
||||||
|
else
|
||||||
|
keys.emplace_back(element);
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -7,6 +7,7 @@ enable_testing()
|
||||||
|
|
||||||
set(TEST_SRCS
|
set(TEST_SRCS
|
||||||
unittest.cpp
|
unittest.cpp
|
||||||
|
query_string_tests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(unittest ${TEST_SRCS})
|
add_executable(unittest ${TEST_SRCS})
|
||||||
|
@ -26,7 +27,7 @@ add_subdirectory(template)
|
||||||
add_subdirectory(multi_file)
|
add_subdirectory(multi_file)
|
||||||
add_subdirectory(external_definition)
|
add_subdirectory(external_definition)
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
if ("ssl" IN_LIST CROW_FEATURES)
|
if (CROW_ENABLE_SSL)
|
||||||
add_subdirectory(ssl)
|
add_subdirectory(ssl)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
#include "crow/query_string.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string buildQueryStr(const std::vector<std::pair<std::string, std::string>>& paramList)
|
||||||
|
{
|
||||||
|
std::string paramsStr{};
|
||||||
|
for (const auto& param : paramList)
|
||||||
|
paramsStr.append(param.first).append(1, '=').append(param.second).append(1, '&');
|
||||||
|
if (!paramsStr.empty())
|
||||||
|
paramsStr.resize(paramsStr.size() - 1);
|
||||||
|
return paramsStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "empty query params" )
|
||||||
|
{
|
||||||
|
const crow::query_string query_params("");
|
||||||
|
const std::vector<std::string> keys = query_params.keys();
|
||||||
|
|
||||||
|
REQUIRE(keys.empty() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "query string keys" )
|
||||||
|
{
|
||||||
|
const std::vector<std::pair<std::string, std::string>> params {
|
||||||
|
{"foo", "bar"}, {"mode", "night"}, {"page", "2"},
|
||||||
|
{"tag", "js"}, {"name", "John Smith"}, {"age", "25"},
|
||||||
|
};
|
||||||
|
|
||||||
|
const crow::query_string query_params("params?" + buildQueryStr(params));
|
||||||
|
const std::vector<std::string> keys = query_params.keys();
|
||||||
|
|
||||||
|
for (const auto& entry: params)
|
||||||
|
{
|
||||||
|
const bool exist = std::any_of(keys.cbegin(), keys.cend(), [&](const std::string& key) {
|
||||||
|
return key == entry.first;});
|
||||||
|
REQUIRE(exist == true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue