Last active
January 10, 2018 10:36
-
-
Save peanutwolf/22bf5096723892d0af175d583b33952b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <cstdlib> | |
#include <restbed> | |
using namespace std; | |
using namespace restbed; | |
class CustomLogger : public Logger | |
{ | |
public: | |
void stop(void) | |
{ | |
return; | |
} | |
void start(const shared_ptr< const Settings >&) | |
{ | |
return; | |
} | |
void log(const Level, const char* format, ...) | |
{ | |
va_list arguments; | |
va_start(arguments, format); | |
vfprintf(stderr, format, arguments); | |
fprintf(stderr, "\n"); | |
va_end(arguments); | |
} | |
void log_if(bool expression, const Level level, const char* format, ...) | |
{ | |
if (expression) | |
{ | |
va_list arguments; | |
va_start(arguments, format); | |
log(level, format, arguments); | |
va_end(arguments); | |
} | |
} | |
}; | |
void get_method_handler( const shared_ptr< Session > session ) | |
{ | |
session->close( OK, "Hello, World!", { { "Content-Length", "13" }, { "Connection", "close" } } ); | |
} | |
int main( const int, const char** ) | |
{ | |
auto resource = make_shared< Resource >( ); | |
resource->set_path( "/resource" ); | |
resource->set_method_handler( "GET", get_method_handler ); | |
auto ssl_settings = make_shared< SSLSettings >( ); | |
ssl_settings->set_http_disabled( true ); | |
ssl_settings->set_client_authentication_enabled(true); | |
ssl_settings->set_private_key(Uri("file://./tmp/ssl/server/key.key")); | |
ssl_settings->set_certificate(Uri("file://./tmp/ssl/server/certificate.crt")); | |
ssl_settings->set_temporary_diffie_hellman(Uri("file://./tmp/ssl/server/dhparam.pem")); | |
ssl_settings->set_certificate_authority_pool(Uri("file://./tmp/ssl/CA/")); | |
auto settings = make_shared< Settings >( ); | |
settings->set_ssl_settings( ssl_settings ); | |
Service service; | |
service.set_logger(make_shared< CustomLogger >()); | |
service.publish( resource ); | |
service.start( settings ); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment