| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #include <Arduino.h> | ||
| 2 | 1 | /** | |
| 3 | 2 | * Example for the ESP32 HTTP(S) Webserver | |
| 4 | 3 | * | |
@@ -115,13 +114,13 @@ void setup() { | |||
| 115 | 114 | // This node will turn an LED on or of. It has two parameters: | |
| 116 | 115 | // 1) The ID of the LED (0..LEDCOUNT) | |
| 117 | 116 | // 2) The new state (0..1) | |
| 118 | - // For more information on URL parameters in general, see the Parameters example. | ||
| 117 | + // For more information on path parameters in general, see the Parameters example. | ||
| 119 | 118 | ResourceNode * nodeSwitch = new ResourceNode("/led/*/*", "POST", &handleSwitch); | |
| 120 | 119 | ||
| 121 | 120 | // We want to use parameter validation. The ResourceNode class provides the method | |
| 122 | - // addURLParamValidator() for that. This method takes two parameters: | ||
| 121 | + // addPathParamValidator() for that. This method takes two parameters: | ||
| 123 | 122 | // 1) The index of the parameter that you want to validate, so for the first wildcard | |
| 124 | - // in the URL pattern that has been specified above, it's 0, and for the second | ||
| 123 | + // in the route pattern that has been specified above, it's 0, and for the second | ||
| 125 | 124 | // parameter it's 1. | |
| 126 | 125 | // 2) A function pointer that takes an std::string as parameter and returns a bool. | |
| 127 | 126 | // That bool should be true if the parameter is considered valid. | |
@@ -138,14 +137,14 @@ void setup() { | |||
| 138 | 137 | ||
| 139 | 138 | // First we will take care of the LED ID. This ID should be... | |
| 140 | 139 | // ... an unsigned integer ... | |
| 141 | - nodeSwitch->addURLParamValidator(0, &validateUnsignedInteger); | ||
| 140 | + nodeSwitch->addPathParamValidator(0, &validateUnsignedInteger); | ||
| 142 | 141 | // ... and within the range of known IDs. | |
| 143 | 142 | // We can treat the parameter safely as integer in this validator, as all validators | |
| 144 | 143 | // are executed in order and validateUnsignedInteger has been run before. | |
| 145 | - nodeSwitch->addURLParamValidator(0, &validateLEDID); | ||
| 144 | + nodeSwitch->addPathParamValidator(0, &validateLEDID); | ||
| 146 | 145 | ||
| 147 | 146 | // The second parameter should either be 0 or 1. We use our custom validateLEDState() validator for this: | |
| 148 | - nodeSwitch->addURLParamValidator(1, &validateLEDState); | ||
| 147 | + nodeSwitch->addPathParamValidator(1, &validateLEDState); | ||
| 149 | 148 | ||
| 150 | 149 | // Not found node | |
| 151 | 150 | ResourceNode * node404 = new ResourceNode("", "GET", &handle404); | |
@@ -232,13 +231,13 @@ void handleSwitch(HTTPRequest * req, HTTPResponse * res) { | |||
| 232 | 231 | ResourceParameters * params = req->getParams(); | |
| 233 | 232 | ||
| 234 | 233 | // Get the LED that is requested. | |
| 235 | - // Note that we can use the parameter directly without further validation, as we | ||
| 234 | + // Note that we can call stoi safely without further validation, as we | ||
| 236 | 235 | // defined that is has to be an unsigned integer and must not be >LEDCOUNT-1 | |
| 237 | - LED * led = &myLEDs[params->getUrlParameterInt(0)]; | ||
| 236 | + LED * led = &myLEDs[std::stoi(params->getPathParameter(0))]; | ||
| 238 | 237 | ||
| 239 | 238 | // Set the state of the LED. The value of the parameter can only be "0" or "1" here, | |
| 240 | 239 | // otherwise the server would not have called the handler. | |
| 241 | - led->setOn(params->getUrlParameter(1)!="0"); | ||
| 240 | + led->setOn(params->getPathParameter(1)!="0"); | ||
| 242 | 241 | ||
| 243 | 242 | // Redirect the user to the main page | |
| 244 | 243 | res->setStatusCode(303); | |
@@ -257,7 +256,7 @@ bool validateLEDState(std::string s) { | |||
| 257 | 256 | // This function is a validator for the first parameter of the POST /led route. | |
| 258 | 257 | // We did check before that the parameter is an integer, now we check its range. | |
| 259 | 258 | bool validateLEDID(std::string s) { | |
| 260 | - uint32_t id = parseUInt(s); | ||
| 259 | + uint32_t id = std::stoul(s); | ||
| 261 | 260 | return id < LEDCOUNT; | |
| 262 | 261 | } | |
| 263 | 262 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,8 @@ HTTPSServer secureServer = HTTPSServer(&cert); | |||
| 53 | 53 | // We declare some handler functions (definition at the end of the file) | |
| 54 | 54 | void handleRoot(HTTPRequest * req, HTTPResponse * res); | |
| 55 | 55 | void handleSVG(HTTPRequest * req, HTTPResponse * res); | |
| 56 | - void handleURLParam(HTTPRequest * req, HTTPResponse * res); | ||
| 56 | + void handleQueryDemo(HTTPRequest * req, HTTPResponse * res); | ||
| 57 | + void handlePathParam(HTTPRequest * req, HTTPResponse * res); | ||
| 57 | 58 | void handle404(HTTPRequest * req, HTTPResponse * res); | |
| 58 | 59 | ||
| 59 | 60 | void setup() { | |
@@ -72,27 +73,31 @@ void setup() { | |||
| 72 | 73 | ||
| 73 | 74 | // For every resource available on the server, we need to create a ResourceNode | |
| 74 | 75 | // The ResourceNode links URL and HTTP method to a handler function | |
| 75 | - ResourceNode * nodeRoot = new ResourceNode("/", "GET", &handleRoot); | ||
| 76 | - ResourceNode * nodeSVG = new ResourceNode("/images/awesome.svg", "GET", &handleSVG); | ||
| 77 | - ResourceNode * node404 = new ResourceNode("", "GET", &handle404); | ||
| 76 | + ResourceNode * nodeRoot = new ResourceNode("/", "GET", &handleRoot); | ||
| 77 | + ResourceNode * nodeSVG = new ResourceNode("/images/awesome.svg", "GET", &handleSVG); | ||
| 78 | + ResourceNode * nodeQueryDemo = new ResourceNode("/queryparams", "GET", &handleQueryDemo); | ||
| 79 | + ResourceNode * node404 = new ResourceNode("", "GET", &handle404); | ||
| 78 | 80 | ||
| 79 | - // URL params | ||
| 81 | + // Path parameters | ||
| 80 | 82 | // If you want (for example) to return a specific instance of an object type by its ID | |
| 81 | 83 | // you can use URLs like /led/1, led/2, ... - And you do not need to register one Resource | |
| 82 | - // Node per ID, but you can use wildcards in the URL definition. The following function | ||
| 83 | - // has to wildcards, and will match for example to /urlparam/foo/bar, where "foo" and "bar" | ||
| 84 | + // Node per ID, but you can use wildcards in the route definition. The following route | ||
| 85 | + // has two wildcards, and will match for example to /urlparam/foo/bar, where "foo" and "bar" | ||
| 84 | 86 | // are accessible parameters in the handler function. | |
| 85 | 87 | // Note: The wildcards can only be used between slashes at the moment (so /urlparam* would | |
| 86 | 88 | // not work). | |
| 87 | - ResourceNode * nodeURLParam = new ResourceNode("/urlparam/*/*", "GET", &handleURLParam); | ||
| 89 | + ResourceNode * nodeURLParam = new ResourceNode("/urlparam/*/*", "GET", &handlePathParam); | ||
| 88 | 90 | ||
| 89 | 91 | // Add the root node to the server | |
| 90 | 92 | secureServer.registerNode(nodeRoot); | |
| 91 | 93 | ||
| 92 | 94 | // Add the SVG image | |
| 93 | 95 | secureServer.registerNode(nodeSVG); | |
| 94 | 96 | ||
| 95 | - // Add the URL param node | ||
| 97 | + // Query parameter demo | ||
| 98 | + secureServer.registerNode(nodeQueryDemo); | ||
| 99 | + | ||
| 100 | + // Add the path parameter | ||
| 96 | 101 | // Note: The order of nodes may become important here. If you have one node for "/led" (e.g. list of LEDs) | |
| 97 | 102 | // and one node for /led/* (LED details), you should register the non-parameterized version first. The server | |
| 98 | 103 | // follows a first-match policy. If you would register the details node first, a call to /led/ will be targetted | |
@@ -126,9 +131,11 @@ void handleRoot(HTTPRequest * req, HTTPResponse * res) { | |||
| 126 | 131 | res->println("<!DOCTYPE html>"); | |
| 127 | 132 | res->println("<html>"); | |
| 128 | 133 | res->println("<head><title>Hello World!</title></head>"); | |
| 134 | + res->println("<style>.info{font-style:italic}</style>"); | ||
| 129 | 135 | res->println("<body>"); | |
| 130 | 136 | ||
| 131 | - res->println("<h1>GET parameters</h1>"); | ||
| 137 | + res->println("<h1>Query Parameters</h1>"); | ||
| 138 | + res->println("<p class=\"info\">The parameters after the question mark in your URL.</p>"); | ||
| 132 | 139 | ||
| 133 | 140 | // Show a form to select a color to colorize the faces | |
| 134 | 141 | // We pass the selection as get parameter "shades" to this very same page, | |
@@ -158,8 +165,8 @@ void handleRoot(HTTPRequest * req, HTTPResponse * res) { | |||
| 158 | 165 | // Depending on the selection we show the images in a specific color shade | |
| 159 | 166 | // Default is dark gray. | |
| 160 | 167 | int r = 63, g = 63, b = 63; | |
| 161 | - if (params->isRequestParameterSet(paramName)) { | ||
| 162 | - std::string paramVal = params->getRequestParameter(paramName); | ||
| 168 | + std::string paramVal; | ||
| 169 | + if (params->getQueryParameter(paramName, paramVal)) { | ||
| 163 | 170 | if (paramVal == "red" || paramVal == "magenta" || paramVal == "yellow" || paramVal == "rainbow") { | |
| 164 | 171 | r = 128 + random(0, 128); | |
| 165 | 172 | } | |
@@ -178,19 +185,21 @@ void handleRoot(HTTPRequest * req, HTTPResponse * res) { | |||
| 178 | 185 | ||
| 179 | 186 | res->print("\" alt=\"Awesome!\" />"); | |
| 180 | 187 | } | |
| 188 | + res->println("<p>You'll find another demo <a href=\"/queryparams?a=42&b&c=13&a=hello\">here</a>.</p>"); | ||
| 181 | 189 | ||
| 182 | - // Link to the URL parameter demo | ||
| 183 | - res->println("<h1>URL parameters</h1>"); | ||
| 190 | + // Link to the path parameter demo | ||
| 191 | + res->println("<h1>Path Parameters</h1>"); | ||
| 192 | + res->println("<p class=\"info\">The parameters derived from placeholders in your path, like /foo/bar.</p>"); | ||
| 184 | 193 | res->println("<p>You'll find the demo <a href=\"/urlparam/foo/bar\">here</a>.</p>"); | |
| 185 | 194 | ||
| 186 | 195 | res->println("</body>"); | |
| 187 | 196 | res->println("</html>"); | |
| 188 | 197 | } | |
| 189 | 198 | ||
| 190 | - // This callback responds with an SVG image to a GET request. The icon is the awesome face. | ||
| 199 | + // This callback responds with an SVG image to a GET request. The icon is the "awesome face". | ||
| 191 | 200 | // (borrowed from https://commons.wikimedia.org/wiki/File:718smiley.svg) | |
| 192 | 201 | // | |
| 193 | - // If the color request parameter is set (so the URL is like awesome.svg?color=fede58), the | ||
| 202 | + // If the color query parameter is set (so the URL is like awesome.svg?color=fede58), the | ||
| 194 | 203 | // background of our awesome face is changed. | |
| 195 | 204 | void handleSVG(HTTPRequest * req, HTTPResponse * res) { | |
| 196 | 205 | // Get access to the parameters | |
@@ -205,10 +214,11 @@ void handleSVG(HTTPRequest * req, HTTPResponse * res) { | |||
| 205 | 214 | // Get request parameter (like awesome.svg?color=ff0000) and validate it | |
| 206 | 215 | std::string colorParamName = "color"; | |
| 207 | 216 | ||
| 208 | - // Check that the parameter is set | ||
| 209 | - if (params->isRequestParameterSet(colorParamName)) { | ||
| 210 | - // Get the value of the parameter | ||
| 211 | - std::string requestColor = params->getRequestParameter(colorParamName); | ||
| 217 | + // Check that the parameter is set and retrieve it. | ||
| 218 | + // The getQueryParameter function will modify the second parameter, but only if the query | ||
| 219 | + // parameter is set. | ||
| 220 | + std::string requestColor; | ||
| 221 | + if (params->getQueryParameter(colorParamName, requestColor)) { | ||
| 212 | 222 | // Check for correct length | |
| 213 | 223 | if (requestColor.length()==6) { | |
| 214 | 224 | bool colorOk = true; | |
@@ -247,10 +257,58 @@ void handleSVG(HTTPRequest * req, HTTPResponse * res) { | |||
| 247 | 257 | res->print("</svg>"); | |
| 248 | 258 | } | |
| 249 | 259 | ||
| 260 | + // This is a more generic demo for the query parameters. It makes use of the iterator | ||
| 261 | + // interface to access them, which is useful if you do not know the paramter names in | ||
| 262 | + // adavance. | ||
| 263 | + void handleQueryDemo(HTTPRequest * req, HTTPResponse * res) { | ||
| 264 | + // A word of warning: In this example, we use the query parameters and directly print | ||
| 265 | + // them into the HTML output. We do this to simplify the demo. NEVER do this in a | ||
| 266 | + // real application, as it allows cross-site-scripting. | ||
| 267 | + res->setHeader("Content-Type", "text/html"); | ||
| 268 | + | ||
| 269 | + res->println("<!DOCTYPE html>"); | ||
| 270 | + res->println("<html>"); | ||
| 271 | + res->println("<head>"); | ||
| 272 | + res->println("<title>Query Parameter Demo</title>"); | ||
| 273 | + res->println("</head>"); | ||
| 274 | + res->println("<body>"); | ||
| 275 | + res->println("<p>The following query paramters have been set:</p>"); | ||
| 276 | + | ||
| 277 | + // Start a table to display the parameters | ||
| 278 | + res->println("<table style=\"border:1px solid black collapse;\">"); | ||
| 279 | + res->println("<tr><th>Key</th><th>Value</th></tr>"); | ||
| 280 | + // Iterate over the parameters. For more information, read about the C++ standard template library, | ||
| 281 | + // especially about vectors and iterators. | ||
| 282 | + ResourceParameters *params = req->getParams(); | ||
| 283 | + for(auto it = params->beginQueryParameters(); it != params->endQueryParameters(); ++it) { | ||
| 284 | + res->print("<tr><td>"); | ||
| 285 | + | ||
| 286 | + // The iterator yields std::pairs of std::strings. The first value contains the parameter key | ||
| 287 | + res->printStd((*it).first); | ||
| 288 | + res->print("</td><td>"); | ||
| 289 | + | ||
| 290 | + // and the second value contains the parameter value | ||
| 291 | + res->printStd((*it).second); | ||
| 292 | + res->println("</td></tr>"); | ||
| 293 | + } | ||
| 294 | + res->println("</table>"); | ||
| 295 | + | ||
| 296 | + // You can retrieve the total parameter count from the parameters instance: | ||
| 297 | + res->print("<p>There are a total of "); | ||
| 298 | + res->print(params->getQueryParameterCount()); | ||
| 299 | + res->print(" parameters, with "); | ||
| 300 | + res->print(params->getQueryParameterCount(true)); | ||
| 301 | + res->println(" unique keys.</p>"); | ||
| 302 | + | ||
| 303 | + res->println("<p>Go <a href=\"/\">back to main page</a>.</p>"); | ||
| 304 | + res->println("</body>"); | ||
| 305 | + res->println("</html>"); | ||
| 306 | + } | ||
| 307 | + | ||
| 250 | 308 | // This is a simple handler function that will show the content of URL parameters. | |
| 251 | 309 | // If you call for example /urlparam/foo/bar, you will get the parameter values | |
| 252 | 310 | // "foo" and "bar" provided by the ResourceParameters. | |
| 253 | - void handleURLParam(HTTPRequest * req, HTTPResponse * res) { | ||
| 311 | + void handlePathParam(HTTPRequest * req, HTTPResponse * res) { | ||
| 254 | 312 | // Get access to the parameters | |
| 255 | 313 | ResourceParameters * params = req->getParams(); | |
| 256 | 314 | ||
@@ -260,19 +318,26 @@ void handleURLParam(HTTPRequest * req, HTTPResponse * res) { | |||
| 260 | 318 | // The url pattern is: /urlparam/*/* | |
| 261 | 319 | // This will make the content for the first parameter available on index 0, | |
| 262 | 320 | // and the second wildcard as index 1. | |
| 321 | + // getPathParameter will - like getQueryParameter - write the value to the second parameter, | ||
| 322 | + // and return true, if the index is valid. Otherwise it returns false and leaves the second | ||
| 323 | + // parameter as it is. | ||
| 263 | 324 | ||
| 325 | + std::string parameter1, parameter2; | ||
| 264 | 326 | // Print the first parameter value | |
| 265 | - res->print("Parameter 1: "); | ||
| 266 | - res->printStd(params->getUrlParameter(0)); | ||
| 327 | + if (params->getPathParameter(0, parameter1)) { | ||
| 328 | + res->print("Parameter 1: "); | ||
| 329 | + res->printStd(parameter1); | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + res->println(); | ||
| 267 | 333 | ||
| 268 | 334 | // Print the second parameter value | |
| 269 | - res->print("\nParameter 2: "); | ||
| 270 | - res->printStd(params->getUrlParameter(1)); | ||
| 335 | + if (params->getPathParameter(1, parameter2)) { | ||
| 336 | + res->print("Parameter 2: "); | ||
| 337 | + res->printStd(parameter2); | ||
| 338 | + } | ||
| 271 | 339 | ||
| 272 | 340 | res->println("\n\nChange the parameters in the URL to see how they get parsed!"); | |
| 273 | - | ||
| 274 | - // Note: If you have objects that are identified by an ID, you may also use | ||
| 275 | - // ResourceParameters::getUrlParameterInt(int) for convenience | ||
| 276 | 341 | } | |
| 277 | 342 | ||
| 278 | 343 | // For details to this function, see the Static-Page example | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,6 +78,16 @@ char contentTypes[][2][32] = { | |||
| 78 | 78 | #include <HTTPResponse.hpp> | |
| 79 | 79 | #include <util.hpp> | |
| 80 | 80 | ||
| 81 | + // The HTTPS Server comes in a separate namespace. For easier use, include it here. | ||
| 82 | + using namespace httpsserver; | ||
| 83 | + | ||
| 84 | + SSLCert * getCertificate(); | ||
| 85 | + void handleSPIFFS(HTTPRequest * req, HTTPResponse * res); | ||
| 86 | + void handleGetUptime(HTTPRequest * req, HTTPResponse * res); | ||
| 87 | + void handleGetEvents(HTTPRequest * req, HTTPResponse * res); | ||
| 88 | + void handlePostEvent(HTTPRequest * req, HTTPResponse * res); | ||
| 89 | + void handleDeleteEvent(HTTPRequest * req, HTTPResponse * res); | ||
| 90 | + | ||
| 81 | 91 | // We use the following struct to store GPIO events: | |
| 82 | 92 | #define MAX_EVENTS 20 | |
| 83 | 93 | struct { | |
@@ -91,9 +101,6 @@ struct { | |||
| 91 | 101 | int state; | |
| 92 | 102 | } events[MAX_EVENTS]; | |
| 93 | 103 | ||
| 94 | - // The HTTPS Server comes in a separate namespace. For easier use, include it here. | ||
| 95 | - using namespace httpsserver; | ||
| 96 | - | ||
| 97 | 104 | // We just create a reference to the server here. We cannot call the constructor unless | |
| 98 | 105 | // we have initialized the SPIFFS and read or created the certificate | |
| 99 | 106 | HTTPSServer * secureServer; | |
@@ -504,7 +511,7 @@ void handlePostEvent(HTTPRequest * req, HTTPResponse * res) { | |||
| 504 | 511 | void handleDeleteEvent(HTTPRequest * req, HTTPResponse * res) { | |
| 505 | 512 | // Access the parameter from the URL. See Parameters example for more details on this | |
| 506 | 513 | ResourceParameters * params = req->getParams(); | |
| 507 | - uint16_t eid = params->getUrlParameterInt(0); | ||
| 514 | + size_t eid = std::atoi(params->getPathParameter(0).c_str()); | ||
| 508 | 515 | ||
| 509 | 516 | if (eid < MAX_EVENTS) { | |
| 510 | 517 | // Set the inactive flag | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -612,8 +612,12 @@ void validationMiddleware(HTTPRequest * req, HTTPResponse * res, std::function<v | |||
| 612 | 612 | // Iterate over the validators and run them | |
| 613 | 613 | std::vector<HTTPValidator*> * validators = node->getValidators(); | |
| 614 | 614 | for(std::vector<HTTPValidator*>::iterator validator = validators->begin(); valid && validator != validators->end(); ++validator) { | |
| 615 | - std::string param = params->getUrlParameter((*validator)->_idx); | ||
| 616 | - valid = ((*validator)->_validatorFunction)(param); | ||
| 615 | + std::string param; | ||
| 616 | + if (params->getPathParameter((*validator)->_idx, param)) { | ||
| 617 | + valid = ((*validator)->_validatorFunction)(param); | ||
| 618 | + } else { | ||
| 619 | + valid = false; | ||
| 620 | + } | ||
| 617 | 621 | } | |
| 618 | 622 | ||
| 619 | 623 | if (valid) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,29 +11,29 @@ namespace httpsserver { | |||
| 11 | 11 | _validators = new std::vector<HTTPValidator*>(); | |
| 12 | 12 | ||
| 13 | 13 | // Count the parameters | |
| 14 | - _urlParamCount = 0; | ||
| 14 | + _pathParamCount = 0; | ||
| 15 | 15 | size_t idx = 0; | |
| 16 | 16 | while((idx = path.find("/*", idx)) != std::string::npos) { | |
| 17 | - _urlParamCount+=1; | ||
| 17 | + _pathParamCount+=1; | ||
| 18 | 18 | // If we don't do this, the same index will be found again... and again... and again... | |
| 19 | 19 | idx+=1; | |
| 20 | 20 | }; | |
| 21 | 21 | ||
| 22 | 22 | // Check if there are parameters | |
| 23 | - if (_urlParamCount > 0) { | ||
| 23 | + if (_pathParamCount > 0) { | ||
| 24 | 24 | // If there are parameters, store their indices | |
| 25 | - _urlParamIdx = new size_t[_urlParamCount]; | ||
| 26 | - for(int i = 0; i < _urlParamCount; i++) { | ||
| 27 | - _urlParamIdx[i] = path.find("/*", i==0 ? 0 : _urlParamIdx[i-1])+1; | ||
| 25 | + _pathParamIdx = new size_t[_pathParamCount]; | ||
| 26 | + for(int i = 0; i < _pathParamCount; i++) { | ||
| 27 | + _pathParamIdx[i] = path.find("/*", i==0 ? 0 : _pathParamIdx[i-1])+1; | ||
| 28 | 28 | } | |
| 29 | 29 | } else { | |
| 30 | - _urlParamIdx = NULL; | ||
| 30 | + _pathParamIdx = NULL; | ||
| 31 | 31 | } | |
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | HTTPNode::~HTTPNode() { | |
| 35 | - if (_urlParamIdx != NULL) { | ||
| 36 | - delete[] _urlParamIdx; | ||
| 35 | + if (_pathParamIdx != NULL) { | ||
| 36 | + delete[] _pathParamIdx; | ||
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | 39 | // Delete validator references | |
@@ -43,23 +43,23 @@ namespace httpsserver { | |||
| 43 | 43 | delete _validators; | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | - bool HTTPNode::hasUrlParameter() { | ||
| 47 | - return _urlParamCount > 0; | ||
| 46 | + bool HTTPNode::hasPathParameter() { | ||
| 47 | + return _pathParamCount > 0; | ||
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | 50 | size_t HTTPNode::getParamIdx(uint8_t idx) { | |
| 51 | - if (idx<_urlParamCount) { | ||
| 52 | - return _urlParamIdx[idx]; | ||
| 51 | + if (idx<_pathParamCount) { | ||
| 52 | + return _pathParamIdx[idx]; | ||
| 53 | 53 | } else { | |
| 54 | 54 | return -1; | |
| 55 | 55 | } | |
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | - uint8_t HTTPNode::getUrlParamCount() { | ||
| 59 | - return _urlParamCount; | ||
| 58 | + size_t HTTPNode::getPathParamCount() { | ||
| 59 | + return _pathParamCount; | ||
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | - void HTTPNode::addURLParamValidator(uint8_t paramIdx, const HTTPValidationFunction * validator) { | ||
| 62 | + void HTTPNode::addPathParamValidator(size_t paramIdx, const HTTPValidationFunction * validator) { | ||
| 63 | 63 | _validators->push_back(new HTTPValidator(paramIdx, validator)); | |
| 64 | 64 | } | |
| 65 | 65 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments