Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 93d535d

Browse files
authored
v1.5.1 to fix String-related bug
### Releases v1.5.1 1. Fix bug related to String in library and examples
1 parent 2c59b06 commit 93d535d

30 files changed

+138
-214
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1414

1515
Please ensure to specify the following:
1616

17-
* Arduino IDE version (e.g. 1.8.18) or Platform.io version
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
1818
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.6.1, etc.)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
@@ -26,7 +26,7 @@ Please ensure to specify the following:
2626
### Example
2727

2828
```
29-
Arduino IDE version: 1.8.18
29+
Arduino IDE version: 1.8.19
3030
RASPBERRY_PI_PICO board
3131
ArduinoCore-mbed v2.6.1
3232
OS: Ubuntu 20.04 LTS

README.md

Lines changed: 57 additions & 93 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.5.1](#releases-v151)
1516
* [Major Releases v1.5.0](#major-releases-v150)
1617
* [Releases v1.4.2](#releases-v142)
1718
* [Releases v1.4.1](#releases-v141)
@@ -35,6 +36,10 @@
3536

3637
## Changelog
3738

39+
### Releases v1.5.1
40+
41+
1. Fix bug related to String in library and examples
42+
3843
### Major Releases v1.5.0
3944

4045
1. Reduce usage of Arduino String with std::string

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WiFiWebServer",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"keywords": "wifi, wi-fi, WebServer, WiFiNINA, WiFi101, ESP32, Portenta-H7, Teensy, SAM DUE, SAMD, STM32, nRF52, rpi-pico, rp2040, HTTP-Client, WebSocket-Client, server, client, websocket, AVR, Mega",
55
"description": "Simple WiFiWebServer, HTTP Client and WebSocket Client library for AVR Mega, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52, RP2040-based (Nano-RP2040-Connect, RASPBERRY_PI_PICO, ESP32/ESP8266, etc.) boards using WiFi, such as WiFiNINA, WiFi101, U-Blox W101, W102, ESP8266/ESP32-AT modules/shields, with functions similar to those of ESP8266/ESP32 WebServer libraries.",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WiFiWebServer
2-
version=1.5.0
2+
version=1.5.1
33
author=Khoi Hoang
44
license=MIT
55
maintainer=Khoi Hoang <khoih.prog@gmail.com>

src/Parsing-impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@file Esp8266WebServer.h
1313
@author Ivan Grokhotkov
1414
15-
Version: 1.5.0
15+
Version: 1.5.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K Hoang 04/10/2021 Change option for PIO `lib_compat_mode` from default `soft` to `strict`. Update Packages Patches
3535
1.4.2 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
3636
1.5.0 K Hoang 19/12/2021 Reduce usage of Arduino String with std::string
37+
1.5.1 K Hoang 25/12/2021 Fix bug
3738
***************************************************************************************************************************************/
3839

3940
#pragma once

src/WiFiHttpClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@file Esp8266WebServer.h
1313
@author Ivan Grokhotkov
1414
15-
Version: 1.5.0
15+
Version: 1.5.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K Hoang 04/10/2021 Change option for PIO `lib_compat_mode` from default `soft` to `strict`. Update Packages Patches
3535
1.4.2 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
3636
1.5.0 K Hoang 19/12/2021 Reduce usage of Arduino String with std::string
37+
1.5.1 K Hoang 25/12/2021 Fix bug
3738
*****************************************************************************************************************************/
3839

3940
// Library to simplify HTTP fetching on Arduino

src/WiFiWebServer-impl.h

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@file Esp8266WebServer.h
1313
@author Ivan Grokhotkov
1414
15-
Version: 1.5.0
15+
Version: 1.5.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K Hoang 04/10/2021 Change option for PIO `lib_compat_mode` from default `soft` to `strict`. Update Packages Patches
3535
1.4.2 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
3636
1.5.0 K Hoang 19/12/2021 Reduce usage of Arduino String with std::string
37+
1.5.1 K Hoang 25/12/2021 Fix bug
3738
***************************************************************************************************************************************/
3839

3940
#pragma once
@@ -398,23 +399,18 @@ void WiFiWebServer::stop()
398399

399400
void WiFiWebServer::sendHeader(const String& name, const String& value, bool first)
400401
{
401-
//String headerLine = name;
402402
WWString headerLine = fromString(name);
403403

404404
headerLine += ": ";
405-
//headerLine += value;
406405
headerLine += fromString(value);
407-
//headerLine += RETURN_NEWLINE;
408406
headerLine += RETURN_NEWLINE;
409407

410408
if (first)
411409
{
412-
//_responseHeaders = headerLine + _responseHeaders;
413410
_responseHeaders = fromWWString(headerLine + fromString(_responseHeaders));
414411
}
415412
else
416413
{
417-
//_responseHeaders += headerLine;
418414
_responseHeaders = fromWWString(fromString(_responseHeaders) + headerLine);
419415
}
420416
}
@@ -427,7 +423,6 @@ void WiFiWebServer::setContentLength(size_t contentLength)
427423

428424
void WiFiWebServer::_prepareHeader(String& response, int code, const char* content_type, size_t contentLength)
429425
{
430-
#if 1
431426
WWString aResponse = fromString(response);
432427

433428
aResponse = "HTTP/1." + fromString(String(_currentVersion)) + " ";
@@ -469,50 +464,7 @@ void WiFiWebServer::_prepareHeader(String& response, int code, const char* conte
469464

470465
response = fromWWString(aResponse);
471466

472-
//MR & KH fix
473-
_responseHeaders = *(new String());
474-
#else
475-
response = "HTTP/1." + String(_currentVersion) + " ";
476-
response += String(code);
477-
response += " ";
478-
response += _responseCodeToString(code);
479-
response += RETURN_NEWLINE;
480-
481-
using namespace mime;
482-
483-
if (!content_type)
484-
content_type = mimeTable[html].mimeType;
485-
486-
sendHeader("Content-Type", content_type, true);
487-
488-
if (_contentLength == CONTENT_LENGTH_NOT_SET)
489-
{
490-
sendHeader("Content-Length", String(contentLength));
491-
}
492-
else if (_contentLength != CONTENT_LENGTH_UNKNOWN)
493-
{
494-
sendHeader("Content-Length", String(_contentLength));
495-
}
496-
else if (_contentLength == CONTENT_LENGTH_UNKNOWN && _currentVersion)
497-
{
498-
//HTTP/1.1 or above client
499-
//let's do chunked
500-
_chunked = true;
501-
sendHeader("Accept-Ranges", "none");
502-
sendHeader("Transfer-Encoding", "chunked");
503-
}
504-
505-
WS_LOGDEBUG(F("_prepareHeader sendHeader Conn close"));
506-
507-
sendHeader("Connection", "close");
508-
509-
response += _responseHeaders;
510-
response += RETURN_NEWLINE;
511-
512-
// RM & KH fix
513-
//_responseHeaders = String();
514-
_responseHeaders = *(new String());
515-
#endif
467+
_responseHeaders = String("");
516468
}
517469

518470
void WiFiWebServer::_prepareHeader(WWString& response, int code, const char* content_type, size_t contentLength)
@@ -554,13 +506,11 @@ void WiFiWebServer::_prepareHeader(WWString& response, int code, const char* con
554506
response += fromString(_responseHeaders);
555507
response += RETURN_NEWLINE;
556508

557-
//MR & KH fix
558-
_responseHeaders = *(new String());
509+
_responseHeaders = String("");
559510
}
560511

561512
void WiFiWebServer::send(int code, const char* content_type, const String& content)
562513
{
563-
//String header;
564514
WWString header;
565515

566516
// Can we asume the following?
@@ -577,14 +527,12 @@ void WiFiWebServer::send(int code, const char* content_type, const String& conte
577527
if (content.length())
578528
{
579529
WS_LOGDEBUG1(F("send1: write header = "), fromWWString(header));
580-
//sendContent(content);
581530
sendContent(content, content.length());
582531
}
583532
}
584533

585534
void WiFiWebServer::send(int code, char* content_type, const String& content, size_t contentLength)
586535
{
587-
//String header;
588536
WWString header;
589537

590538
WS_LOGDEBUG1(F("send2: len = "), contentLength);
@@ -698,7 +646,6 @@ void WiFiWebServer::send_P(int code, PGM_P content_type, PGM_P content)
698646

699647
void WiFiWebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength)
700648
{
701-
//String header;
702649
WWString header;
703650

704651
char type[64];
@@ -773,7 +720,9 @@ void WiFiWebServer::sendContent_P(PGM_P content, size_t size)
773720
}
774721

775722
#if (ESP32 || ESP8266)
723+
776724
#include "FS.h"
725+
777726
void WiFiWebServer::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header)
778727
{
779728
_addRequestHandler(new StaticFileRequestHandler(fs, path, uri, cache_header));
@@ -795,6 +744,7 @@ void WiFiWebServer::_streamFileCore(const size_t fileSize, const String &fileNam
795744
send(200, contentType, emptyString);
796745
}
797746
#endif
747+
798748
//////
799749

800750
String WiFiWebServer::arg(const String& name)
@@ -969,9 +919,7 @@ void WiFiWebServer::_handleRequest()
969919
//_currentUri = String();
970920
WS_LOGDEBUG(F("_handleRequest: Done Clear _currentUri"));
971921
#else
972-
// RM & KH fix
973-
//_currentUri = String();
974-
_currentUri = *(new String());
922+
_responseHeaders = String("");
975923
#endif
976924
}
977925

src/WiFiWebServer.h

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@file Esp8266WebServer.h
1313
@author Ivan Grokhotkov
1414
15-
Version: 1.5.0
15+
Version: 1.5.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
@@ -34,17 +34,18 @@
3434
1.4.1 K Hoang 04/10/2021 Change option for PIO `lib_compat_mode` from default `soft` to `strict`. Update Packages Patches
3535
1.4.2 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
3636
1.5.0 K Hoang 19/12/2021 Reduce usage of Arduino String with std::string
37+
1.5.1 K Hoang 25/12/2021 Fix bug
3738
***************************************************************************************************************************************/
3839

3940
#pragma once
4041

41-
#define WIFI_WEBSERVER_VERSION "WiFiWebServer v1.5.0"
42+
#define WIFI_WEBSERVER_VERSION "WiFiWebServer v1.5.1"
4243

4344
#define WIFI_WEBSERVER_VERSION_MAJOR 1
4445
#define WIFI_WEBSERVER_VERSION_MINOR 5
45-
#define WIFI_WEBSERVER_VERSION_PATCH 0
46+
#define WIFI_WEBSERVER_VERSION_PATCH 1
4647

47-
#define WIFI_WEBSERVER_VERSION_INT 1005000
48+
#define WIFI_WEBSERVER_VERSION_INT 1005001
4849

4950
#define USE_NEW_WEBSERVER_VERSION true
5051

@@ -314,17 +315,17 @@ class WiFiWebServer
314315
}
315316

316317
//KH
317-
#if USE_NEW_WEBSERVER_VERSION
318+
#if USE_NEW_WEBSERVER_VERSION
318319
HTTPUpload& upload()
319320
{
320321
return *_currentUpload;
321322
}
322-
#else
323+
#else
323324
HTTPUpload& upload()
324325
{
325326
return _currentUpload;
326327
}
327-
#endif
328+
#endif
328329

329330
String arg(const String& name); // get request argument value by name
330331
String arg(int i); // get request argument value by number
@@ -366,8 +367,7 @@ class WiFiWebServer
366367

367368
static String urlDecode(const String& text);
368369

369-
#if 0
370-
370+
#if !(ESP32 || ESP8266)
371371
template<typename T> size_t streamFile(T &file, const String& contentType)
372372
{
373373
using namespace mime;
@@ -382,25 +382,9 @@ class WiFiWebServer
382382

383383
return _currentClient.write(file);
384384
}
385-
#endif
386-
387-
388-
#if !(ESP32 || ESP8266)
389-
template<typename T> size_t streamFile(T &file, const String& contentType)
390-
{
391-
using namespace mime;
392-
setContentLength(file.size());
393-
394-
if (String(file.name()).endsWith(mimeTable[gz].endsWith) && contentType != mimeTable[gz].mimeType && contentType != mimeTable[none].mimeType)
395-
{
396-
sendHeader("Content-Encoding", "gzip");
397-
}
398-
399-
send(200, contentType, "");
400-
401-
return _currentClient.write(file);
402-
}
403-
#else
385+
386+
#else
387+
404388
void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); // serve static pages from file system
405389

406390
// Handle a GET request by sending a response header and stream file content to response body
@@ -420,7 +404,7 @@ class WiFiWebServer
420404
}
421405
return contentLength;
422406
}
423-
#endif
407+
#endif
424408

425409
protected:
426410
void _addRequestHandler(RequestHandler* handler);
@@ -446,7 +430,7 @@ class WiFiWebServer
446430
void _prepareHeader(WWString& response, int code, const char* content_type, size_t contentLength);
447431
bool _collectHeader(const char* headerName, const char* headerValue);
448432

449-
#if (ESP32 || ESP8266)
433+
#if (ESP32 || ESP8266)
450434
void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType);
451435

452436
template<typename T>
@@ -465,7 +449,7 @@ class WiFiWebServer
465449

466450
return contentLength;
467451
}
468-
#endif
452+
#endif
469453

470454
struct RequestArgument
471455
{
@@ -492,14 +476,14 @@ class WiFiWebServer
492476
RequestArgument* _currentArgs = nullptr;
493477

494478
//KH = nullptr
495-
#if USE_NEW_WEBSERVER_VERSION
479+
#if USE_NEW_WEBSERVER_VERSION
496480
HTTPUpload* _currentUpload = nullptr;
497481
int _postArgsLen;
498482
RequestArgument* _postArgs = nullptr;
499483

500-
#else
484+
#else
501485
HTTPUpload _currentUpload;
502-
#endif
486+
#endif
503487

504488
int _headerKeysCount;
505489
RequestArgument* _currentHeaders = nullptr;

0 commit comments

Comments
 (0)