Skip to content

Commit 78dc30f

Browse files
committed
Added support for standard HTTP methods for WebDAC and REST APIs.
1 parent 70b259f commit 78dc30f

3 files changed

Lines changed: 106 additions & 25 deletions

File tree

src/ESPAsyncWebServer.h

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,65 @@ class AsyncMiddlewareChain;
9595
namespace AsyncWebRequestMethod {
9696
// The long name here is because we sometimes include this in the global namespace
9797
enum AsyncWebRequestMethodType {
98-
HTTP_GET = 1 << 0,
99-
HTTP_POST = 1 << 1,
100-
HTTP_DELETE = 1 << 2,
101-
HTTP_PUT = 1 << 3,
102-
HTTP_PATCH = 1 << 4,
103-
HTTP_HEAD = 1 << 5,
104-
HTTP_OPTIONS = 1 << 6,
105-
HTTP_PROPFIND = 1 << 7,
106-
HTTP_LOCK = 1 << 8,
107-
HTTP_UNLOCK = 1 << 9,
108-
HTTP_PROPPATCH = 1 << 10,
109-
HTTP_MKCOL = 1 << 11,
110-
HTTP_MOVE = 1 << 12,
111-
HTTP_COPY = 1 << 13,
112-
HTTP_RESERVED = 1 << 14,
113-
11498
HTTP_UNKNOWN = 0,
115-
HTTP_INVALID = 1 << 15 // Sentinel
99+
100+
HTTP_DELETE = 1 << 0,
101+
HTTP_GET = 1 << 1,
102+
HTTP_HEAD = 1 << 2,
103+
HTTP_POST = 1 << 3,
104+
HTTP_PUT = 1 << 4,
105+
106+
/* pathological */
107+
HTTP_CONNECT = 1 << 5,
108+
HTTP_OPTIONS = 1 << 6,
109+
HTTP_TRACE = 1 << 7,
110+
111+
/* WebDAV */
112+
HTTP_COPY = 1 << 8,
113+
HTTP_LOCK = 1 << 9,
114+
HTTP_MKCOL = 1 << 10,
115+
HTTP_MOVE = 1 << 11,
116+
HTTP_PROPFIND = 1 << 12,
117+
HTTP_PROPPATCH = 1 << 13,
118+
HTTP_SEARCH = 1 << 14,
119+
HTTP_UNLOCK = 1 << 15,
120+
HTTP_BIND = 1 << 16,
121+
HTTP_REBIND = 1 << 17,
122+
HTTP_UNBIND = 1 << 18,
123+
HTTP_ACL = 1 << 19,
124+
125+
/* subversion */
126+
// HTTP_REPORT
127+
// HTTP_MKACTIVITY
128+
// HTTP_CHECKOUT
129+
// HTTP_MERGE
130+
131+
/* upnp */
132+
// HTTP_MSEARCH
133+
// HTTP_NOTIFY
134+
// HTTP_SUBSCRIBE
135+
// HTTP_UNSUBSCRIBE
136+
137+
/* RFC-5789 */
138+
HTTP_PATCH = 1 << 20,
139+
HTTP_PURGE = 1 << 21,
140+
141+
/* CalDAV */
142+
// HTTP_MKCALENDAR
143+
144+
/* RFC-2068, section 19.6.1.2 */
145+
HTTP_LINK = 1 << 22,
146+
HTTP_UNLINK = 1 << 23,
147+
148+
/* icecast */
149+
// HTTP_SOURCE
150+
151+
HTTP_INVALID = 1 << 31 // Sentinel
116152
};
117153
}; // namespace AsyncWebRequestMethod
118154

119155
typedef AsyncWebRequestMethod::AsyncWebRequestMethodType WebRequestMethod;
120-
typedef uint16_t WebRequestMethodComposite;
156+
typedef uint32_t WebRequestMethodComposite;
121157

122158
namespace AsyncWebRequestMethod {
123159
constexpr WebRequestMethodComposite HTTP_ALL = static_cast<WebRequestMethodComposite>(HTTP_INVALID) - 1;

src/WebRequest.cpp

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,16 @@ WebRequestMethod stringToMethod(const String &m) {
13221322
return AsyncWebRequestMethod::HTTP_HEAD;
13231323
} else if (m == T_OPTIONS) {
13241324
return AsyncWebRequestMethod::HTTP_OPTIONS;
1325+
} else if (m == T_TRACE) {
1326+
return AsyncWebRequestMethod::HTTP_TRACE;
1327+
} else if (m == T_CONNECT) {
1328+
return AsyncWebRequestMethod::HTTP_CONNECT;
1329+
} else if (m == T_PURGE) {
1330+
return AsyncWebRequestMethod::HTTP_PURGE;
1331+
} else if (m == T_LINK) {
1332+
return AsyncWebRequestMethod::HTTP_LINK;
1333+
} else if (m == T_UNLINK) {
1334+
return AsyncWebRequestMethod::HTTP_UNLINK;
13251335
} else if (m == T_PROPFIND) {
13261336
return AsyncWebRequestMethod::HTTP_PROPFIND;
13271337
} else if (m == T_LOCK) {
@@ -1336,27 +1346,52 @@ WebRequestMethod stringToMethod(const String &m) {
13361346
return AsyncWebRequestMethod::HTTP_MOVE;
13371347
} else if (m == T_COPY) {
13381348
return AsyncWebRequestMethod::HTTP_COPY;
1349+
} else if (m == T_SEARCH) {
1350+
return AsyncWebRequestMethod::HTTP_SEARCH;
1351+
} else if (m == T_BIND) {
1352+
return AsyncWebRequestMethod::HTTP_BIND;
1353+
} else if (m == T_REBIND) {
1354+
return AsyncWebRequestMethod::HTTP_REBIND;
1355+
} else if (m == T_UNBIND) {
1356+
return AsyncWebRequestMethod::HTTP_UNBIND;
1357+
} else if (m == T_ACL) {
1358+
return AsyncWebRequestMethod::HTTP_ACL;
13391359
} else {
13401360
return AsyncWebRequestMethod::HTTP_INVALID;
13411361
}
13421362
}
13431363

13441364
const char *methodToString(WebRequestMethod method) {
13451365
switch (method) {
1366+
case AsyncWebRequestMethod::HTTP_DELETE: return T_DELETE;
13461367
case AsyncWebRequestMethod::HTTP_GET: return T_GET;
1368+
case AsyncWebRequestMethod::HTTP_HEAD: return T_HEAD;
13471369
case AsyncWebRequestMethod::HTTP_POST: return T_POST;
1348-
case AsyncWebRequestMethod::HTTP_DELETE: return T_DELETE;
13491370
case AsyncWebRequestMethod::HTTP_PUT: return T_PUT;
1350-
case AsyncWebRequestMethod::HTTP_PATCH: return T_PATCH;
1351-
case AsyncWebRequestMethod::HTTP_HEAD: return T_HEAD;
1371+
/* pathological */
1372+
case AsyncWebRequestMethod::HTTP_CONNECT: return T_CONNECT;
13521373
case AsyncWebRequestMethod::HTTP_OPTIONS: return T_OPTIONS;
1353-
case AsyncWebRequestMethod::HTTP_PROPFIND: return T_PROPFIND;
1374+
case AsyncWebRequestMethod::HTTP_TRACE: return T_TRACE;
1375+
/* WebDAV */
1376+
case AsyncWebRequestMethod::HTTP_COPY: return T_COPY;
13541377
case AsyncWebRequestMethod::HTTP_LOCK: return T_LOCK;
1355-
case AsyncWebRequestMethod::HTTP_UNLOCK: return T_UNLOCK;
1356-
case AsyncWebRequestMethod::HTTP_PROPPATCH: return T_PROPPATCH;
13571378
case AsyncWebRequestMethod::HTTP_MKCOL: return T_MKCOL;
13581379
case AsyncWebRequestMethod::HTTP_MOVE: return T_MOVE;
1359-
case AsyncWebRequestMethod::HTTP_COPY: return T_COPY;
1380+
case AsyncWebRequestMethod::HTTP_PROPFIND: return T_PROPFIND;
1381+
case AsyncWebRequestMethod::HTTP_PROPPATCH: return T_PROPPATCH;
1382+
case AsyncWebRequestMethod::HTTP_SEARCH: return T_SEARCH;
1383+
case AsyncWebRequestMethod::HTTP_UNLOCK: return T_UNLOCK;
1384+
case AsyncWebRequestMethod::HTTP_BIND: return T_BIND;
1385+
case AsyncWebRequestMethod::HTTP_REBIND: return T_REBIND;
1386+
case AsyncWebRequestMethod::HTTP_UNBIND: return T_UNBIND;
1387+
case AsyncWebRequestMethod::HTTP_ACL: return T_ACL;
1388+
/* RFC-5789 */
1389+
case AsyncWebRequestMethod::HTTP_PATCH: return T_PATCH;
1390+
case AsyncWebRequestMethod::HTTP_PURGE: return T_PURGE;
1391+
/* RFC-2068, section 19.6.1.2 */
1392+
case AsyncWebRequestMethod::HTTP_LINK: return T_LINK;
1393+
case AsyncWebRequestMethod::HTTP_UNLINK: return T_UNLINK;
1394+
// Unsupported
13601395
default: return T_UNKNOWN;
13611396
}
13621397
}

src/literals.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ static constexpr const char T_MKCOL[] = "MKCOL";
119119
static constexpr const char T_MOVE[] = "MOVE";
120120
static constexpr const char T_COPY[] = "COPY";
121121
static constexpr const char T_UNKNOWN[] = "UNKNOWN";
122+
static constexpr const char T_CONNECT[] = "CONNECT";
123+
static constexpr const char T_TRACE[] = "TRACE";
124+
static constexpr const char T_SEARCH[] = "SEARCH";
125+
static constexpr const char T_BIND[] = "BIND";
126+
static constexpr const char T_REBIND[] = "REBIND";
127+
static constexpr const char T_UNBIND[] = "UNBIND";
128+
static constexpr const char T_ACL[] = "ACL";
129+
static constexpr const char T_PURGE[] = "PURGE";
130+
static constexpr const char T_LINK[] = "LINK";
131+
static constexpr const char T_UNLINK[] = "UNLINK";
122132

123133
// Req content types
124134
static constexpr const char T_RCT_NOT_USED[] = "RCT_NOT_USED";

0 commit comments

Comments
 (0)