Skip to content

Commit c1a6cca

Browse files
committed
Fix WebServer and examples
1 parent 5d15850 commit c1a6cca

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

Diff for: libraries/WebServer/examples/FSBrowser/FSBrowser.ino

+15-5
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,25 @@ String getContentType(String filename) {
8282
return "text/plain";
8383
}
8484

85+
bool exists(String path){
86+
bool yes = false;
87+
File file = SPIFFS.open(path, "r");
88+
if(!file.isDirectory()){
89+
yes = true;
90+
}
91+
file.close();
92+
return yes;
93+
}
94+
8595
bool handleFileRead(String path) {
8696
DBG_OUTPUT_PORT.println("handleFileRead: " + path);
8797
if (path.endsWith("/")) {
8898
path += "index.htm";
8999
}
90100
String contentType = getContentType(path);
91101
String pathWithGz = path + ".gz";
92-
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
93-
if (SPIFFS.exists(pathWithGz)) {
102+
if (exists(pathWithGz) || exists(path)) {
103+
if (exists(pathWithGz)) {
94104
path += ".gz";
95105
}
96106
File file = SPIFFS.open(path, "r");
@@ -136,7 +146,7 @@ void handleFileDelete() {
136146
if (path == "/") {
137147
return server.send(500, "text/plain", "BAD PATH");
138148
}
139-
if (!SPIFFS.exists(path)) {
149+
if (!exists(path)) {
140150
return server.send(404, "text/plain", "FileNotFound");
141151
}
142152
SPIFFS.remove(path);
@@ -153,7 +163,7 @@ void handleFileCreate() {
153163
if (path == "/") {
154164
return server.send(500, "text/plain", "BAD PATH");
155165
}
156-
if (SPIFFS.exists(path)) {
166+
if (exists(path)) {
157167
return server.send(500, "text/plain", "FILE EXISTS");
158168
}
159169
File file = SPIFFS.open(path, "w");
@@ -189,7 +199,7 @@ void handleFileList() {
189199
output += "{\"type\":\"";
190200
output += (file.isDirectory()) ? "dir" : "file";
191201
output += "\",\"name\":\"";
192-
output += String(file.name());
202+
output += String(file.name()).substring(1);
193203
output += "\"}";
194204
file = root.openNextFile();
195205
}

Diff for: libraries/WebServer/examples/WebUpdate/WebUpdate.ino

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <WiFiClient.h>
77
#include <WebServer.h>
88
#include <ESPmDNS.h>
9+
#include <Update.h>
910

1011
const char* host = "esp32-webupdate";
1112
const char* ssid = "........";

Diff for: libraries/WebServer/src/detail/mimetable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace mime
55
{
66

77
// Table of extension->MIME strings stored in PROGMEM, needs to be global due to GCC section typing rules
8-
const Entry mimeTable[maxType] ICACHE_RODATA_ATTR =
8+
const Entry mimeTable[maxType] =
99
{
1010
{ ".html", "text/html" },
1111
{ ".htm", "text/html" },

Diff for: libraries/WiFi/src/WiFiClient.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size)
240240
return write(buf, size);
241241
}
242242

243+
size_t WiFiClient::write(Stream&stream)
244+
{
245+
uint8_t * buf = (uint8_t *)malloc(1360);
246+
if(!buf){
247+
return 0;
248+
}
249+
size_t toRead = 0, toWrite = 0, written = 0;
250+
size_t available = stream.available();
251+
while(available){
252+
toRead = (available > 1360)?1360:available;
253+
toWrite = stream.readBytes(buf, toRead);
254+
written += write(buf, toWrite);
255+
available = stream.available();
256+
}
257+
free(buf);
258+
return written;
259+
}
260+
243261
int WiFiClient::read(uint8_t *buf, size_t size)
244262
{
245263
if(!available()) {

Diff for: libraries/WiFi/src/WiFiClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class WiFiClient : public Client
4545
size_t write(uint8_t data);
4646
size_t write(const uint8_t *buf, size_t size);
4747
size_t write_P(PGM_P buf, size_t size);
48+
size_t write(Stream&stream);
4849
int available();
4950
int read();
5051
int read(uint8_t *buf, size_t size);

0 commit comments

Comments
 (0)