@@ -15,16 +15,55 @@ class FunctionRequestHandler : public RequestHandler {
15
15
, _uri(uri)
16
16
, _method(method)
17
17
{
18
+ int numParams = 0 , start = 0 ;
19
+ do {
20
+ start = _uri.indexOf (" {}" , start);
21
+ if (start > 0 ) {
22
+ numParams++;
23
+ start += 2 ;
24
+ }
25
+ } while (start > 0 );
26
+ pathArgs.resize (numParams);
18
27
}
19
28
20
29
bool canHandle (HTTPMethod requestMethod, String requestUri) override {
21
30
if (_method != HTTP_ANY && _method != requestMethod)
22
31
return false ;
23
32
24
- if (requestUri != _uri)
25
- return false ;
33
+ if (_uri == requestUri)
34
+ return true ;
35
+
36
+ size_t uriLength = _uri.length ();
37
+ unsigned int pathArgIndex = 0 ;
38
+ unsigned int requestUriIndex = 0 ;
39
+ for (unsigned int i = 0 ; i < uriLength; i++, requestUriIndex++) {
40
+ char uriChar = _uri[i];
41
+ char requestUriChar = requestUri[requestUriIndex];
42
+
43
+ if (uriChar == requestUriChar)
44
+ continue ;
45
+ if (uriChar != ' {' )
46
+ return false ;
47
+
48
+ i += 2 ; // index of char after '}'
49
+ if (i >= uriLength) {
50
+ // there is no char after '}'
51
+ pathArgs[pathArgIndex] = requestUri.substring (requestUriIndex);
52
+ return pathArgs[pathArgIndex].indexOf (" /" ) == -1 ; // path argument may not contain a '/'
53
+ }
54
+ else
55
+ {
56
+ char charEnd = _uri[i];
57
+ int uriIndex = requestUri.indexOf (charEnd, requestUriIndex);
58
+ if (uriIndex < 0 )
59
+ return false ;
60
+ pathArgs[pathArgIndex] = requestUri.substring (requestUriIndex, uriIndex);
61
+ requestUriIndex = (unsigned int ) uriIndex;
62
+ }
63
+ pathArgIndex++;
64
+ }
26
65
27
- return true ;
66
+ return requestUriIndex >= requestUri. length () ;
28
67
}
29
68
30
69
bool canUpload (String requestUri) override {
0 commit comments