Skip to main content

resolve_request_path

Function resolve_request_path 

Source
pub fn resolve_request_path(
    config: &PathResolverConfig<'_>,
    request_path: &str,
) -> ResolvedPath
Expand description

Resolves a URL path to determine what resource should be served.

This is a pure function that performs filesystem checks (through config.vault) but no I/O operations like reading file contents. It determines the type of resource to serve.

§Resolution Order

  1. Direct file match in base_dir → StaticFile
  2. Directory with configured index file (e.g., index.md) → MarkdownFile
  3. Path with trailing slash matching a markdown file (e.g., /foo/ → foo.md) → MarkdownFile
  4. File in static folder → StaticFile
  5. Directory with index.{markdown_ext} → MarkdownFile
  6. Directory without index → DirectoryListing
  7. Tag source index (e.g., /tags/) → TagSourceIndex (if source matches config)
  8. Tag page (e.g., /tags/rust/) → TagPage (if source matches config)
  9. Nothing matches → NotFound

Note: Filesystem paths (steps 1-6) always take precedence over tag URLs (steps 7-8). If a file or directory named “tags” exists, it will be served instead of the tag index.

§Security

Path traversal attacks (e.g., ../../../etc/passwd) are blocked by validating that all resolved paths remain within the configured base directory.