Skip to content

Commit 0edba2e

Browse files
Add WebServer, WebServerSecure, HTTPUpdateServer, HTTPUpdateServerSecure (#791)
* Add HTTP-parser lib to support ESP32 WebServer * Add WebServer from ESP32. Only supports HTTP * Separate HTTP server from the network server Instead of managing the WiFiServer/WiFiServerSecure in the same object as the HTTP handling, split them into separate objects. This lets HTTP and HTTPS servers work without templates or duplicating code. The HTTP block just gets a `WiFiClient*` and works with that to only do HTTP processing, while the upper object handles the appropriate server and client types. * Add HTTPS server * Clean up some THandlerFunction refs * Refactor into a template-ized WebServer/WebServerSecure * Add DNSServer examples which need WebServer * Fix CoreMutex infinite recursion crash Core could crash while Serial debugging was going on and prints were happening from LWIP/IRQ land and the main app. * Add HTTPUpdateServer(Secure) * Add MIME include, optimize WebServer::send(size,len) When send()ing a large buffer, the WebServer::send() call would actually convert that buffer into a String (i.e. duplicate it, and potential issues with embedded \0s in binary data). Make a simple override to send(size, len) to allow writing from the source buffer instead. * Fix WiFiClient::send(Stream), add FSBrowser example
1 parent c501306 commit 0edba2e

File tree

81 files changed

+6837
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+6837
-58
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Run codespell
2121
uses: codespell-project/actions-codespell@master
2222
with:
23-
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib
23+
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino
2424
ignore_words_list: ser,dout
2525

2626
# Consistent style

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ system
33
tools/dist
44
docs/_build
55
ota/build
6-
tools/libpico/build
6+
tools/libpico/build
7+
platform.local.txt

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
[submodule "ota/uzlib"]
3535
path = ota/uzlib
3636
url = https://github.com/pfalcon/uzlib.git
37+
[submodule "libraries/http_parser/lib/http-parser"]
38+
path = libraries/http-parser/lib/http-parser
39+
url = https://github.com/nodejs/http-parser.git

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ The installed tools include a version of OpenOCD (in the pqt-openocd directory)
147147
* Adafruit TinyUSB Arduino (USB mouse, keyboard, flash drive, generic HID, CDC Serial, MIDI, WebUSB, others)
148148
* Generic Arduino USB Serial, Keyboard, and Mouse emulation
149149
* WiFi (Pico W)
150+
* HTTP client and server (WebServer)
151+
* SSL/TLS/HTTPS
150152
* Over-the-Air (OTA) upgrades
151153
* Filesystems (LittleFS and SD/SDFS)
152154
* Multicore support (setup1() and loop1())
@@ -187,7 +189,10 @@ If you want to contribute or have bugfixes, drop me a note at <earlephilhower@ya
187189
* [lwIP](https://savannah.nongnu.org/projects/lwip/) is (c) the Swedish Institute of Computer Science and licenced under the BSD license.
188190
* [BearSSL](https://bearssl.org) library written by Thomas Pornin, is distributed under the [MIT License](https://bearssl.org/#legal-details).
189191
* [UZLib](https://github.com/pfalcon/uzlib) is copyright (c) 2003 Joergen Ibsen and distributed under the zlib license.
190-
* [LEAmDMS](https://github.com/LaborEtArs/ESP8266mDNS) is copyright multiple authors and distributed under the MIT license.
192+
* [LEAmDNS](https://github.com/LaborEtArs/ESP8266mDNS) is copyright multiple authors and distributed under the MIT license.
193+
* [http-parser](https://github.com/nodejs/http-parser) is copyright Joyent, Inc. and other Node contributors.
194+
* WebServer code modified from the [ESP32 WebServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer) and is copyright (c) 2015 Ivan Grokhotkov and others
195+
191196
192197
-Earle F. Philhower, III
193198

cores/rp2040/Arduino.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ extern bool __isFreeRTOS;
9090
#define HAVE_HWSERIAL1
9191
#define HAVE_HWSERIAL2
9292

93+
// PSTR/etc.
94+
#ifndef FPSTR
95+
#define FPSTR (const char *)
96+
#endif
97+
98+
#ifndef PGM_VOID_P
99+
#define PGM_VOID_P void *
100+
#endif
101+
93102
#ifdef __cplusplus
94103

95104
#ifdef USE_TINYUSB

cores/rp2040/CoreMutex.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727

2828
class CoreMutex {
2929
public:
30-
CoreMutex(mutex_t *mutex) {
30+
CoreMutex(mutex_t *mutex, bool debugEnable = true) {
3131
uint32_t owner;
3232
_mutex = mutex;
3333
_acquired = false;
3434
if (!mutex_try_enter(_mutex, &owner)) {
3535
if (owner == get_core_num()) { // Deadlock!
36-
DEBUGCORE("CoreMutex - Deadlock detected!\n");
36+
if (debugEnable) {
37+
DEBUGCORE("CoreMutex - Deadlock detected!\n");
38+
}
3739
return;
3840
}
3941
mutex_enter_blocking(_mutex);

cores/rp2040/SerialUSB.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void SerialUSB::end() {
6464
}
6565

6666
int SerialUSB::peek() {
67-
CoreMutex m(&__usb_mutex);
67+
CoreMutex m(&__usb_mutex, false);
6868
if (!_running || !m) {
6969
return 0;
7070
}
@@ -74,7 +74,7 @@ int SerialUSB::peek() {
7474
}
7575

7676
int SerialUSB::read() {
77-
CoreMutex m(&__usb_mutex);
77+
CoreMutex m(&__usb_mutex, false);
7878
if (!_running || !m) {
7979
return -1;
8080
}
@@ -86,7 +86,7 @@ int SerialUSB::read() {
8686
}
8787

8888
int SerialUSB::available() {
89-
CoreMutex m(&__usb_mutex);
89+
CoreMutex m(&__usb_mutex, false);
9090
if (!_running || !m) {
9191
return 0;
9292
}
@@ -95,7 +95,7 @@ int SerialUSB::available() {
9595
}
9696

9797
int SerialUSB::availableForWrite() {
98-
CoreMutex m(&__usb_mutex);
98+
CoreMutex m(&__usb_mutex, false);
9999
if (!_running || !m) {
100100
return 0;
101101
}
@@ -104,7 +104,7 @@ int SerialUSB::availableForWrite() {
104104
}
105105

106106
void SerialUSB::flush() {
107-
CoreMutex m(&__usb_mutex);
107+
CoreMutex m(&__usb_mutex, false);
108108
if (!_running || !m) {
109109
return;
110110
}
@@ -117,7 +117,7 @@ size_t SerialUSB::write(uint8_t c) {
117117
}
118118

119119
size_t SerialUSB::write(const uint8_t *buf, size_t length) {
120-
CoreMutex m(&__usb_mutex);
120+
CoreMutex m(&__usb_mutex, false);
121121
if (!_running || !m) {
122122
return 0;
123123
}
@@ -155,7 +155,7 @@ size_t SerialUSB::write(const uint8_t *buf, size_t length) {
155155
}
156156

157157
SerialUSB::operator bool() {
158-
CoreMutex m(&__usb_mutex);
158+
CoreMutex m(&__usb_mutex, false);
159159
if (!_running || !m) {
160160
return false;
161161
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)