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

Commit e308402

Browse files
authored
Merge pull request #7 from tothtechnika/master
Fix base64 encoding of websocket client key and progmem support for webserver
2 parents 88503ca + 3e21c74 commit e308402

7 files changed

+421
-304
lines changed

src/AsyncWebRequest_STM32.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/****************************************************************************************************************************
22
AsyncWebRequest_STM32.cpp - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet
3-
3+
44
For STM32 with LAN8720 (STM32F4/F7) or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
5-
5+
66
AsyncWebServer_STM32 is a library for the STM32 with LAN8720 or built-in LAN8742A Ethernet WebServer
7-
7+
88
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
99
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_STM32
1010
Licensed under MIT license
11-
11+
1212
Version: 1.3.0
13-
13+
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
1616
1.2.3 K Hoang 02/09/2020 Initial coding for STM32 for built-in Ethernet (Nucleo-144, DISCOVERY, etc).
@@ -1007,6 +1007,14 @@ void AsyncWebServerRequest::send(AsyncWebServerResponse *response)
10071007
}
10081008
}
10091009

1010+
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback){
1011+
return new AsyncProgmemResponse(code, contentType, content, len, callback);
1012+
}
1013+
1014+
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback){
1015+
return beginResponse_P(code, contentType, (const uint8_t *)content, strlen_P(content), callback);
1016+
}
1017+
10101018
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, const String& content)
10111019
{
10121020
return new AsyncBasicResponse(code, contentType, content);
@@ -1063,31 +1071,31 @@ void AsyncWebServerRequest::redirect(const String& url)
10631071
}
10641072

10651073
bool AsyncWebServerRequest::authenticate(const char * username, const char * password, const char * realm, bool passwordIsHash)
1066-
{
1074+
{
10671075
LOGDEBUG1("AsyncWebServerRequest::authenticate: auth-len =", _authorization.length());
1068-
1076+
10691077
if (_authorization.length())
1070-
{
1078+
{
10711079
if (_isDigest)
10721080
{
10731081
LOGDEBUG("AsyncWebServerRequest::authenticate: _isDigest");
1074-
1082+
10751083
return checkDigestAuthentication(_authorization.c_str(), methodToString(), username, password, realm, passwordIsHash, NULL, NULL, NULL);
10761084
}
10771085
else if (!passwordIsHash)
10781086
{
10791087
LOGDEBUG("AsyncWebServerRequest::authenticate: !passwordIsHash");
1080-
1088+
10811089
return checkBasicAuthentication(_authorization.c_str(), username, password);
10821090
}
10831091
else
10841092
{
10851093
LOGDEBUG("AsyncWebServerRequest::authenticate: Using password _authorization.equals");
1086-
1094+
10871095
return _authorization.equals(password);
10881096
}
10891097
}
1090-
1098+
10911099
LOGDEBUG("AsyncWebServerRequest::authenticate: failed, len = 0");
10921100

10931101
return false;
@@ -1293,12 +1301,12 @@ bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType
12931301

12941302
if ((erct1 != RCT_NOT_USED) && (erct1 == _reqconntype))
12951303
res = true;
1296-
1304+
12971305
if ((erct2 != RCT_NOT_USED) && (erct2 == _reqconntype))
12981306
res = true;
1299-
1307+
13001308
if ((erct3 != RCT_NOT_USED) && (erct3 == _reqconntype))
13011309
res = true;
1302-
1310+
13031311
return res;
13041312
}

src/AsyncWebResponseImpl_STM32.h

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/****************************************************************************************************************************
22
AsyncWebResponseImpl_STM32.h - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet
3-
3+
44
For STM32 with LAN8720 (STM32F4/F7) or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
5-
5+
66
AsyncWebServer_STM32 is a library for the STM32 with LAN8720 or built-in LAN8742A Ethernet WebServer
7-
7+
88
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
99
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_STM32
1010
Licensed under MIT license
11-
11+
1212
Version: 1.3.0
13-
13+
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
1616
1.2.3 K Hoang 02/09/2020 Initial coding for STM32 for built-in Ethernet (Nucleo-144, DISCOVERY, etc).
@@ -35,24 +35,25 @@
3535
#include <vector>
3636
// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max.
3737

38-
class AsyncBasicResponse: public AsyncWebServerResponse
38+
39+
class AsyncBasicResponse: public AsyncWebServerResponse
3940
{
4041
private:
4142
String _content;
42-
43+
4344
public:
4445
AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String());
4546
void _respond(AsyncWebServerRequest *request);
46-
47+
4748
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
48-
49-
bool _sourceValid() const
49+
50+
bool _sourceValid() const
5051
{
5152
return true;
5253
}
5354
};
5455

55-
class AsyncAbstractResponse: public AsyncWebServerResponse
56+
class AsyncAbstractResponse: public AsyncWebServerResponse
5657
{
5758
private:
5859
String _head;
@@ -63,21 +64,21 @@ class AsyncAbstractResponse: public AsyncWebServerResponse
6364
std::vector<uint8_t> _cache;
6465
size_t _readDataFromCacheOrContent(uint8_t* data, const size_t len);
6566
size_t _fillBufferAndProcessTemplates(uint8_t* buf, size_t maxLen);
66-
67+
6768
protected:
6869
AwsTemplateProcessor _callback;
69-
70+
7071
public:
7172
AsyncAbstractResponse(AwsTemplateProcessor callback = nullptr);
7273
void _respond(AsyncWebServerRequest *request);
7374
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
74-
75-
bool _sourceValid() const
75+
76+
bool _sourceValid() const
7677
{
7778
return false;
7879
}
79-
80-
virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused)))
80+
81+
virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused)))
8182
{
8283
return 0;
8384
}
@@ -89,72 +90,81 @@ class AsyncAbstractResponse: public AsyncWebServerResponse
8990

9091
#define TEMPLATE_PARAM_NAME_LENGTH 32
9192

92-
class AsyncStreamResponse: public AsyncAbstractResponse
93+
class AsyncStreamResponse: public AsyncAbstractResponse
9394
{
9495
private:
9596
Stream *_content;
96-
97+
9798
public:
9899
AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
99-
100-
bool _sourceValid() const
100+
101+
bool _sourceValid() const
101102
{
102103
return !!(_content);
103104
}
104-
105+
105106
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
106107
};
107108

108-
class AsyncCallbackResponse: public AsyncAbstractResponse
109+
class AsyncCallbackResponse: public AsyncAbstractResponse
109110
{
110111
private:
111112
AwsResponseFiller _content;
112113
size_t _filledLength;
113-
114+
114115
public:
115116
AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr);
116-
117-
bool _sourceValid() const
117+
118+
bool _sourceValid() const
118119
{
119120
return !!(_content);
120121
}
121-
122+
122123
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
123124
};
124125

125-
class AsyncChunkedResponse: public AsyncAbstractResponse
126+
class AsyncChunkedResponse: public AsyncAbstractResponse
126127
{
127128
private:
128129
AwsResponseFiller _content;
129130
size_t _filledLength;
130-
131+
131132
public:
132133
AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr);
133-
134-
bool _sourceValid() const
134+
135+
bool _sourceValid() const
135136
{
136137
return !!(_content);
137138
}
138-
139+
139140
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
140141
};
141142

142143
class cbuf;
144+
class AsyncProgmemResponse: public AsyncAbstractResponse {
145+
private:
146+
const uint8_t * _content;
147+
size_t _readLength;
148+
public:
149+
AsyncProgmemResponse(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
150+
bool _sourceValid() const { return true; }
151+
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
152+
};
143153

144-
class AsyncResponseStream: public AsyncAbstractResponse, public Print
154+
class AsyncResponseStream: public AsyncAbstractResponse, public Print
145155
{
146156
private:
147157
cbuf *_content;
148-
158+
149159
public:
150160
AsyncResponseStream(const String& contentType, size_t bufferSize);
151161
~AsyncResponseStream();
152-
153-
bool _sourceValid() const
162+
163+
bool _sourceValid() const
154164
{
155165
return (_state < RESPONSE_END);
156166
}
157-
167+
158168
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
159169
size_t write(const uint8_t *data, size_t len);
160170
size_t write(uint8_t data);

0 commit comments

Comments
 (0)