Add backup files, add test data for doc root, etc.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#include "webcc/encoding.h"
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef WEBCC_ENCODING_H_
|
||||
#define WEBCC_ENCODING_H_
|
||||
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
|
||||
namespace webcc {
|
||||
|
||||
std::string Utf16ToUtf8(const std::wstring& utf16_string) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(utf16_string);
|
||||
}
|
||||
|
||||
std::wstring Utf8ToUtf16(const std::string& utf8_string) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.from_bytes(utf8_string);
|
||||
}
|
||||
|
||||
} // namespace webcc
|
||||
|
||||
#endif // WEBCC_ENCODING_H_
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
#include "boost/asio/ip/tcp.hpp"
|
||||
|
||||
|
||||
using Endpoint = boost::asio::ip::tcp::endpoint;
|
||||
using Endpoints = boost::asio::ip::tcp::resolver::results_type;
|
||||
|
||||
void PrintEndpoint(std::ostream& ostream, const Endpoint& endpoint);
|
||||
|
||||
void PrintEndpoints(std::ostream& ostream, const Endpoints& endpoints);
|
||||
|
||||
std::string EndpointToString(const Endpoint& endpoint);
|
||||
|
||||
|
||||
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
|
||||
void PrintEndpoint(std::ostream& ostream, const Endpoint& endpoint) {
|
||||
ostream << endpoint;
|
||||
if (endpoint.protocol() == tcp::v4()) {
|
||||
ostream << ", v4";
|
||||
} else if (endpoint.protocol() == tcp::v6()) {
|
||||
ostream << ", v6";
|
||||
}
|
||||
}
|
||||
|
||||
void PrintEndpoints(std::ostream& ostream, const Endpoints& endpoints) {
|
||||
ostream << "Endpoints: " << endpoints.size() << std::endl;
|
||||
tcp::resolver::results_type::iterator it = endpoints.begin();
|
||||
for (; it != endpoints.end(); ++it) {
|
||||
ostream << " - ";
|
||||
PrintEndpoint(ostream, it->endpoint());
|
||||
ostream << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::string EndpointToString(const Endpoint& endpoint) {
|
||||
std::stringstream ss;
|
||||
PrintEndpoint(ss, endpoint);
|
||||
return ss.str();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
function fixedEncodeURIComponent(str) {
|
||||
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
|
||||
return '%' + c.charCodeAt(0).toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
console.log(encodeURIComponent('[!\'()*]'))
|
||||
console.log(fixedEncodeURIComponent('[!\'()*]'))
|
||||
|
||||
const subDelims = '!$&\\()*+,;=';
|
||||
console.log(encodeURIComponent(subDelims))
|
||||
console.log(fixedEncodeURIComponent(subDelims))
|
||||
|
||||
const unreserved = 'aAzZ09-._~';
|
||||
console.log(encodeURIComponent(unreserved))
|
||||
console.log(fixedEncodeURIComponent(unreserved))
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "webcc/service_manager.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MyService : public webcc::Service {
|
||||
public:
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request,
|
||||
const webcc::UrlArgs& args) override {
|
||||
return webcc::ResponseBuilder{}.OK()();
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/*
|
||||
TEST(ServiceManagerTest, URL_RegexBasic) {
|
||||
webcc::ServiceManager service_manager;
|
||||
|
||||
service_manager.Add(std::make_shared<MyService>(), "/instance/(\\d+)", true);
|
||||
|
||||
std::string url = "/instance/12345";
|
||||
webcc::UrlArgs args;
|
||||
|
||||
webcc::ServicePtr service = service_manager.Get(url, &args);
|
||||
|
||||
EXPECT_TRUE(!!service);
|
||||
|
||||
EXPECT_EQ(1, args.size());
|
||||
EXPECT_EQ("12345", args[0]);
|
||||
|
||||
url = "/instance/abcde";
|
||||
args.clear();
|
||||
service = service_manager.Get(url, &args);
|
||||
|
||||
EXPECT_FALSE(!!service);
|
||||
}
|
||||
|
||||
TEST(RestServiceManagerTest, URL_RegexMultiple) {
|
||||
webcc::ServiceManager service_manager;
|
||||
|
||||
service_manager.Add(std::make_shared<MyService>(),
|
||||
"/study/(\\d+)/series/(\\d+)/instance/(\\d+)", true);
|
||||
|
||||
std::string url = "/study/1/series/2/instance/3";
|
||||
webcc::UrlArgs args;
|
||||
|
||||
webcc::ServicePtr service = service_manager.Get(url, &args);
|
||||
|
||||
EXPECT_TRUE(!!service);
|
||||
|
||||
EXPECT_EQ(3, args.size());
|
||||
EXPECT_EQ("1", args[0]);
|
||||
EXPECT_EQ("2", args[1]);
|
||||
EXPECT_EQ("3", args[2]);
|
||||
|
||||
url = "/study/a/series/b/instance/c";
|
||||
args.clear();
|
||||
service = service_manager.Get(url, &args);
|
||||
|
||||
EXPECT_FALSE(!!service);
|
||||
}
|
||||
|
||||
TEST(RestServiceManagerTest, URL_NonRegex) {
|
||||
webcc::ServiceManager service_manager;
|
||||
|
||||
service_manager.Add(std::make_shared<MyService>(), "/instances", false);
|
||||
|
||||
std::string url = "/instances";
|
||||
webcc::UrlArgs args;
|
||||
|
||||
webcc::ServicePtr service = service_manager.Get(url, &args);
|
||||
|
||||
EXPECT_TRUE(!!service);
|
||||
EXPECT_TRUE(args.empty());
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
static void Sleep(int seconds) {
|
||||
if (seconds > 0) {
|
||||
LOG_INFO("Sleep %d seconds...", seconds);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(seconds));
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "If |seconds| is provided, the server will sleep, for testing "
|
||||
<< "timeout, before " << std::endl
|
||||
<< "send back each response." << std::endl;
|
||||
Reference in New Issue
Block a user