Add basic ServerName example & impl.

This commit is contained in:
Alex Hultman
2020-08-17 02:49:36 +02:00
parent cf0a21e33b
commit d14d31ce47
4 changed files with 33 additions and 2 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
EXAMPLE_FILES := HelloWorld EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync
EXAMPLE_FILES := HelloWorld ServerName EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync
THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded
override CXXFLAGS += -lpthread -Wconversion -std=c++17 -Isrc -IuSockets/src
override LDFLAGS += uSockets/*.o -lz
+24
View File
@@ -0,0 +1,24 @@
#include "App.h"
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
int main() {
/* Overly simple hello world app (SNI) */
uWS::SSLApp({
.key_file_name = "../misc/key.pem",
.cert_file_name = "../misc/cert.pem",
.passphrase = "1234"
}).addServerName("localhost", {
.key_file_name = "../misc/key.pem",
.cert_file_name = "../misc/cert.pem",
.passphrase = "1234"
}).get("/*", [](auto *res, auto *req) {
res->end("Hello world!");
}).listen(3000, [](auto *token) {
if (token) {
std::cout << "Listening on port " << 3000 << std::endl;
}
}).run();
std::cout << "Failed to listen on port 3000" << std::endl;
}
+7
View File
@@ -38,6 +38,13 @@ private:
public:
/* Server name */
TemplatedApp &&addServerName(std::string hostname_pattern, us_socket_context_options_t options = {}) {
us_socket_context_add_server_name(SSL, (struct us_socket_context_t *) httpContext, hostname_pattern.c_str(), options);
return std::move(*this);
}
/* Returns the SSL_CTX of this app, or nullptr. */
void *getNativeHandle() {
return us_socket_context_get_native_handle(SSL, (struct us_socket_context_t *) httpContext);