|
@@ -1,6 +1,7 @@
|
|
|
#include "kbf/http/server.h"
|
|
|
|
|
|
#include <esp_log.h>
|
|
|
+#include <esp_https_server.h>
|
|
|
#include <memory>
|
|
|
|
|
|
#include "kbf/macros.h"
|
|
@@ -14,7 +15,7 @@ http::Server &http::Server::route(http::Server::Route route) {
|
|
|
}
|
|
|
|
|
|
http::Server &http::Server::start(int port) {
|
|
|
- ESP_LOGI(TAG, "starting HTTP server on port %d", port);
|
|
|
+ ESP_LOGI(TAG, "start(%d)", port);
|
|
|
if (running) {
|
|
|
ESP_LOGE(TAG, "server already running");
|
|
|
ABORT("fix me");
|
|
@@ -26,6 +27,41 @@ http::Server &http::Server::start(int port) {
|
|
|
config.stack_size = 16384;
|
|
|
CHECK(httpd_start(&handle, &config));
|
|
|
|
|
|
+ registerUriHandlers();
|
|
|
+
|
|
|
+ running = true;
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+http::Server &http::Server::startSSL(int port) {
|
|
|
+ ESP_LOGI(TAG, "startSSL(%d)", port);
|
|
|
+ if (running) {
|
|
|
+ ESP_LOGE(TAG, "server already running");
|
|
|
+ ABORT("fix me");
|
|
|
+ }
|
|
|
+
|
|
|
+ handle = nullptr;
|
|
|
+ httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
|
|
|
+
|
|
|
+ extern const unsigned char cacert_pem_start[] asm("_binary_cacert_pem_start");
|
|
|
+ extern const unsigned char cacert_pem_end[] asm("_binary_cacert_pem_end");
|
|
|
+ conf.cacert_pem = cacert_pem_start;
|
|
|
+ conf.cacert_len = cacert_pem_end - cacert_pem_start;
|
|
|
+
|
|
|
+ extern const unsigned char prvtkey_pem_start[] asm("_binary_prvtkey_pem_start");
|
|
|
+ extern const unsigned char prvtkey_pem_end[] asm("_binary_prvtkey_pem_end");
|
|
|
+ conf.prvtkey_pem = prvtkey_pem_start;
|
|
|
+ conf.prvtkey_len = prvtkey_pem_end - prvtkey_pem_start;
|
|
|
+
|
|
|
+ CHECK(httpd_ssl_start(&handle, &conf));
|
|
|
+
|
|
|
+ registerUriHandlers();
|
|
|
+
|
|
|
+ running = true;
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+void http::Server::registerUriHandlers() {
|
|
|
ESP_LOGI(TAG, "registering URI handlers");
|
|
|
for (auto &route : routes) {
|
|
|
ESP_LOGI(TAG, " method: %d; uri: %s", static_cast<int>(route.method), route.uri.c_str());
|
|
@@ -37,9 +73,6 @@ http::Server &http::Server::start(int port) {
|
|
|
};
|
|
|
CHECK(httpd_register_uri_handler(handle, &uriHandler));
|
|
|
}
|
|
|
-
|
|
|
- running = true;
|
|
|
- return *this;
|
|
|
}
|
|
|
|
|
|
void http::Server::stop() {
|