ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
handle-root.cpp
Go to the documentation of this file.
1 /*
2  handle-root.cpp - ESP3D http handle
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "../../../include/esp3d_config.h"
21 #if defined (HTTP_FEATURE)
22 #include "../http_server.h"
23 //embedded response file if no files on ESP Filesystem
24 #include "../embedded.h"
25 #if defined (ARDUINO_ARCH_ESP32)
26 #include <WebServer.h>
27 #endif //ARDUINO_ARCH_ESP32
28 #if defined (ARDUINO_ARCH_ESP8266)
29 #include <ESP8266WebServer.h>
30 #endif //ARDUINO_ARCH_ESP8266
31 #include "../../filesystem/esp_filesystem.h"
32 //Root of Webserver/////////////////////////////////////////////////////
33 void HTTP_Server::handle_root()
34 {
35  String path = "/index.html";
36  String contentType = getContentType(path.c_str());
37  String pathWithGz = path + ".gz";
38  //if have a index.html or gzip version this is default root page
39  if((ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) && !_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback")!="yes") {
40  if(ESP_FileSystem::exists(pathWithGz.c_str())) {
41  _webserver->sendHeader("Content-Encoding", "gzip");
42  path = pathWithGz;
43  }
44  if(!StreamFSFile(path.c_str(),contentType.c_str())) {
45  log_esp3d("Stream `%s` failed", path.c_str());
46  }
47  return;
48  }
49  //if no lets launch the default content
50  _webserver->sendHeader("Content-Encoding", "gzip");
51  _webserver->send_P(200,"text/html",(const char *)tool_html_gz,tool_html_gz_size);
52 }
53 #endif //HTTP_FEATURE
tool_html_gz_size
#define tool_html_gz_size
Definition: embedded.h:28
log_esp3d
#define log_esp3d(format,...)
Definition: debug_esp3d.h:29
ESP_FileSystem::exists
static bool exists(const char *path)