| 350 | |
| 351 | |
| 352 | Future<bool> FilesProcess::authorize( |
| 353 | string requestedPath, |
| 354 | const Option<Principal>& principal) |
| 355 | { |
| 356 | // The path may contain a trailing forward slash. Since we store the |
| 357 | // authorization callbacks without the trailing slash, we must remove it here, |
| 358 | // if present. |
| 359 | const string trimmedPath = |
| 360 | strings::remove(requestedPath, |
| 361 | stringify(os::PATH_SEPARATOR), strings::SUFFIX); |
| 362 | |
| 363 | if (authorizations.count(trimmedPath) > 0) { |
| 364 | return authorizations[trimmedPath](principal); |
| 365 | } |
| 366 | |
| 367 | do { |
| 368 | requestedPath = Path(requestedPath).dirname(); |
| 369 | |
| 370 | if (authorizations.count(requestedPath) > 0) { |
| 371 | return authorizations[requestedPath](principal); |
| 372 | } |
| 373 | } while (Path(requestedPath).dirname() != requestedPath); |
| 374 | |
| 375 | // requestedPath does not require authorization. |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | Future<http::Response> FilesProcess::_browse( |