missingServerName and updated ServerName example
This commit is contained in:
+15
-6
@@ -4,21 +4,30 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* Overly simple hello world app (SNI) */
|
/* Overly simple hello world app (SNI) */
|
||||||
uWS::SSLApp({
|
uWS::SSLApp app = uWS::SSLApp({
|
||||||
.key_file_name = "../misc/key.pem",
|
|
||||||
.cert_file_name = "../misc/cert.pem",
|
|
||||||
.passphrase = "1234"
|
|
||||||
}).addServerName("localhost", {
|
|
||||||
.key_file_name = "../misc/key.pem",
|
.key_file_name = "../misc/key.pem",
|
||||||
.cert_file_name = "../misc/cert.pem",
|
.cert_file_name = "../misc/cert.pem",
|
||||||
.passphrase = "1234"
|
.passphrase = "1234"
|
||||||
|
}).missingServerName([&app](const char *hostname) {
|
||||||
|
|
||||||
|
printf("We are missing server name: <%s>\n", hostname);
|
||||||
|
|
||||||
|
/* Assume it is localhost, so add it */
|
||||||
|
app.addServerName("localhost", {
|
||||||
|
.key_file_name = "../misc/key.pem",
|
||||||
|
.cert_file_name = "../misc/cert.pem",
|
||||||
|
.passphrase = "1234"
|
||||||
|
});
|
||||||
|
|
||||||
}).get("/*", [](auto *res, auto *req) {
|
}).get("/*", [](auto *res, auto *req) {
|
||||||
res->end("Hello world!");
|
res->end("Hello world!");
|
||||||
}).listen(3000, [](auto *token) {
|
}).listen(3000, [](auto *token) {
|
||||||
if (token) {
|
if (token) {
|
||||||
std::cout << "Listening on port " << 3000 << std::endl;
|
std::cout << "Listening on port " << 3000 << std::endl;
|
||||||
}
|
}
|
||||||
}).run();
|
});
|
||||||
|
|
||||||
|
app.run();
|
||||||
|
|
||||||
std::cout << "Failed to listen on port 3000" << std::endl;
|
std::cout << "Failed to listen on port 3000" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,19 @@ public:
|
|||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TemplatedApp &&missingServerName(fu2::unique_function<void(const char *hostname)> handler) {
|
||||||
|
|
||||||
|
httpContext->getSocketContextData()->missingServerNameHandler = std::move(handler);
|
||||||
|
|
||||||
|
us_socket_context_on_server_name(SSL, (struct us_socket_context_t *) httpContext, [](struct us_socket_context_t *context, const char *hostname) {
|
||||||
|
|
||||||
|
/* This is the only requirements of being friends with HttpContextData */
|
||||||
|
HttpContext<SSL> *httpContext = (HttpContext<SSL> *) context;
|
||||||
|
httpContext->getSocketContextData()->missingServerNameHandler(hostname);
|
||||||
|
});
|
||||||
|
return std::move(*this);
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the SSL_CTX of this app, or nullptr. */
|
/* Returns the SSL_CTX of this app, or nullptr. */
|
||||||
void *getNativeHandle() {
|
void *getNativeHandle() {
|
||||||
return us_socket_context_get_native_handle(SSL, (struct us_socket_context_t *) httpContext);
|
return us_socket_context_get_native_handle(SSL, (struct us_socket_context_t *) httpContext);
|
||||||
|
|||||||
@@ -31,9 +31,12 @@ template <bool SSL>
|
|||||||
struct alignas(16) HttpContextData {
|
struct alignas(16) HttpContextData {
|
||||||
template <bool> friend struct HttpContext;
|
template <bool> friend struct HttpContext;
|
||||||
template <bool> friend struct HttpResponse;
|
template <bool> friend struct HttpResponse;
|
||||||
|
template <bool> friend struct TemplatedApp;
|
||||||
private:
|
private:
|
||||||
std::vector<fu2::unique_function<void(HttpResponse<SSL> *, int)>> filterHandlers;
|
std::vector<fu2::unique_function<void(HttpResponse<SSL> *, int)>> filterHandlers;
|
||||||
|
|
||||||
|
fu2::unique_function<void(const char *hostname)> missingServerNameHandler;
|
||||||
|
|
||||||
struct RouterData {
|
struct RouterData {
|
||||||
HttpResponse<SSL> *httpResponse;
|
HttpResponse<SSL> *httpResponse;
|
||||||
HttpRequest *httpRequest;
|
HttpRequest *httpRequest;
|
||||||
|
|||||||
+1
-1
Submodule uSockets updated: cd62d4409b...42bdf7fbd2
Reference in New Issue
Block a user