@@ -197,10 +197,10 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
197
197
public:
198
198
#if ARDUINOJSON_VERSION_MAJOR == 6
199
199
AsyncCallbackJsonWebHandler (const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
200
- : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384 ) {}
200
+ : _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384 ) {}
201
201
#else
202
202
AsyncCallbackJsonWebHandler (const String& uri, ArJsonRequestHandlerFunction onRequest)
203
- : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384 ) {}
203
+ : _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384 ) {}
204
204
#endif
205
205
206
206
void setMethod (WebRequestMethodComposite method) { _method = method; }
@@ -211,22 +211,29 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
211
211
if (!_onRequest)
212
212
return false ;
213
213
214
- if (!(_method & request->method ()))
214
+ WebRequestMethodComposite request_method = request->method ();
215
+ if (!(_method & request_method))
215
216
return false ;
216
217
217
218
if (_uri.length () && (_uri != request->url () && !request->url ().startsWith (_uri + " /" )))
218
219
return false ;
219
220
220
- if (!request->contentType ().equalsIgnoreCase (JSON_MIMETYPE))
221
+ if (request_method != HTTP_GET && !request->contentType ().equalsIgnoreCase (JSON_MIMETYPE))
221
222
return false ;
222
223
223
224
request->addInterestingHeader (" ANY" );
224
225
return true ;
225
226
}
226
227
227
228
virtual void handleRequest (AsyncWebServerRequest* request) override final {
229
+ if ((_username != " " && _password != " " ) && !request->authenticate (_username.c_str (), _password.c_str ()))
230
+ return request->requestAuthentication ();
228
231
if (_onRequest) {
229
- if (request->_tempObject != NULL ) {
232
+ if (request->method () == HTTP_GET) {
233
+ JsonVariant json;
234
+ _onRequest (request, json);
235
+ return ;
236
+ } else if (request->_tempObject != NULL ) {
230
237
231
238
#if ARDUINOJSON_VERSION_MAJOR == 5
232
239
DynamicJsonBuffer jsonBuffer;
0 commit comments