Add backup files, add test data for doc root, etc.
parent
2a25340ce4
commit
43d9dcab25
@ -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;
|
@ -1,2 +1,2 @@
|
|||||||
|
**upload**: files for testing upload using multipart form data. (`examples/form_client.cc`)
|
||||||
**upload**: files for testing upload.
|
**www**: doc root for testing static file server. (`examples/static_file_server.cc`)
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
Remember
|
||||||
|
BY CHRISTINA ROSSETTI
|
||||||
|
|
||||||
|
Remember me when I am gone away,
|
||||||
|
Gone far away into the silent land;
|
||||||
|
When you can no more hold me by the hand,
|
||||||
|
Nor I half turn to go yet turning stay.
|
||||||
|
Remember me when no more day by day
|
||||||
|
You tell me of our future that you plann'd:
|
||||||
|
Only remember me; you understand
|
||||||
|
It will be late to counsel then or pray.
|
||||||
|
Yet if you should forget me for a while
|
||||||
|
And afterwards remember, do not grieve:
|
||||||
|
For if the darkness and corruption leave
|
||||||
|
A vestige of the thoughts that once I had,
|
||||||
|
Better by far you should forget and smile
|
||||||
|
Than that you should remember and be sad.
|
Binary file not shown.
After Width: | Height: | Size: 138 KiB |
@ -0,0 +1 @@
|
|||||||
|
Hello, World!
|
Loading…
Reference in New Issue