|
26 | 26 | #include "esp3d_log.h" |
27 | 27 | #include "esp3d_settings.h" |
28 | 28 | #include "esp3d_string.h" |
| 29 | +#include "esp3d_version.h" |
29 | 30 | #include "esp_tls_crypto.h" |
30 | 31 | #include "esp_wifi.h" |
31 | 32 | #include "filesystem/esp3d_globalfs.h" |
@@ -220,10 +221,9 @@ bool ESP3DHttpService::begin() { |
220 | 221 | return true; |
221 | 222 | } |
222 | 223 | httpd_config_t config = HTTPD_DEFAULT_CONFIG(); |
223 | | - uint32_t intValue = |
224 | | - esp3dTftsettings.readUint32(ESP3DSettingIndex::esp3d_http_port); |
| 224 | + _port = esp3dTftsettings.readUint32(ESP3DSettingIndex::esp3d_http_port); |
225 | 225 | // HTTP port |
226 | | - config.server_port = intValue; |
| 226 | + config.server_port = _port; |
227 | 227 | // Http server core |
228 | 228 | config.core_id = 0; |
229 | 229 | // stack size (default 4096) |
@@ -997,6 +997,37 @@ ESP3DAuthenticationLevel ESP3DHttpService::getAuthenticationLevel( |
997 | 997 | return ESP3DAuthenticationLevel::admin; |
998 | 998 | #endif // #if ESP3D_AUTHENTICATION_FEATURE |
999 | 999 | } |
| 1000 | + |
| 1001 | +esp_err_t ESP3DHttpService::httpd_resp_set_http_hdr(httpd_req_t *req) { |
| 1002 | + esp_err_t err = ESP_OK; |
| 1003 | + |
| 1004 | + err = httpd_resp_set_hdr(req, "User-Agent", |
| 1005 | + "ESP3D-TFT-HttpServer/1.0 (" CONFIG_IDF_TARGET |
| 1006 | + "; Firmware/" ESP3D_TFT_VERSION |
| 1007 | + "; Platform/RTOS; Embedded; http://www.esp3d.io)"); |
| 1008 | + if (err != ESP_OK) { |
| 1009 | + esp3d_log_e("httpd_resp_set_hdr failed for User-Agent"); |
| 1010 | + return err; |
| 1011 | + } |
| 1012 | + |
| 1013 | + static std::string host = ""; |
| 1014 | + if (host.empty()) { |
| 1015 | + host = "http://"; |
| 1016 | + host += esp3dNetwork.getLocalIpString(); |
| 1017 | + if (esp3dHttpService.getPort() != 80) { |
| 1018 | + host += ":"; |
| 1019 | + host += esp3dHttpService.getPort(); |
| 1020 | + } |
| 1021 | + } |
| 1022 | + |
| 1023 | + err = httpd_resp_set_hdr(req, "Host", host.c_str()); |
| 1024 | + if (err != ESP_OK) { |
| 1025 | + esp3d_log_e("httpd_resp_set_hdr failed for Host"); |
| 1026 | + return err; |
| 1027 | + } |
| 1028 | + return err; |
| 1029 | +} |
| 1030 | + |
1000 | 1031 | esp_err_t ESP3DHttpService::streamFile(const char *path, httpd_req_t *req) { |
1001 | 1032 | esp_err_t res = ESP_OK; |
1002 | 1033 | if (!_started || !_server) { |
|
0 commit comments