missingServerName and updated ServerName example

This commit is contained in:
Alex Hultman
2020-08-17 05:39:54 +02:00
parent 77aced05f8
commit f69282c478
4 changed files with 32 additions and 7 deletions
+13
View File
@@ -51,6 +51,19 @@ public:
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. */
void *getNativeHandle() {
return us_socket_context_get_native_handle(SSL, (struct us_socket_context_t *) httpContext);
+3
View File
@@ -31,9 +31,12 @@ template <bool SSL>
struct alignas(16) HttpContextData {
template <bool> friend struct HttpContext;
template <bool> friend struct HttpResponse;
template <bool> friend struct TemplatedApp;
private:
std::vector<fu2::unique_function<void(HttpResponse<SSL> *, int)>> filterHandlers;
fu2::unique_function<void(const char *hostname)> missingServerNameHandler;
struct RouterData {
HttpResponse<SSL> *httpResponse;
HttpRequest *httpRequest;