Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 63b5303

Browse files
Lucme-no-dev
authored andcommitted
Allow callback when request disconnects (me-no-dev#284)
* Allow callback when request disconnects * Use typedef std::function<void(void)> ArDisconnectHandler
1 parent 8604f67 commit 63b5303

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/ESPAsyncWebServer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef enum {
6262
HTTP_ANY = 0b01111111,
6363
} WebRequestMethod;
6464
typedef uint8_t WebRequestMethodComposite;
65+
typedef std::function<void(void)> ArDisconnectHandler;
6566

6667
/*
6768
* PARAMETER :: Chainable object to hold GET/POST and FILE parameters
@@ -128,6 +129,7 @@ class AsyncWebServerRequest {
128129
AsyncWebHandler* _handler;
129130
AsyncWebServerResponse* _response;
130131
StringArray _interestingHeaders;
132+
ArDisconnectHandler _onDisconnectfn;
131133

132134
String _temp;
133135
uint8_t _parseState;
@@ -202,6 +204,7 @@ class AsyncWebServerRequest {
202204
const char * requestedConnTypeToString() const;
203205
RequestedConnectionType requestedConnType() const { return _reqconntype; }
204206
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, RequestedConnectionType erct3 = RCT_NOT_USED);
207+
void onDisconnect (ArDisconnectHandler fn);
205208

206209
//hash is the string representation of:
207210
// base64(user:pass) for basic or

src/WebRequest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,15 @@ void AsyncWebServerRequest::_onTimeout(uint32_t time){
214214
_client->close();
215215
}
216216

217+
void AsyncWebServerRequest::onDisconnect (ArDisconnectHandler fn){
218+
_onDisconnectfn=fn;
219+
}
220+
217221
void AsyncWebServerRequest::_onDisconnect(){
218222
//os_printf("d\n");
223+
if(_onDisconnectfn) {
224+
_onDisconnectfn();
225+
}
219226
_server->_handleDisconnect(this);
220227
}
221228

0 commit comments

Comments
 (0)