Class RequestTarget

java.lang.Object
com.iizix.jetty.RequestTarget

public final class RequestTarget extends Object
The target of a request, as every rule of the web tier compares it (CC-FIX-JETTY-TARGET-NORMALIZE, IIZI-JETTY-PAGE-TARGET-AS-WRITTEN-BYPASSES-REFUSALS).

Why. A rule that refuses, gates or prepares a page compared the path of the request as the client WROTE it (HttpServletRequest.getRequestURI()), while the web server finds its file by the decoded path without its dot segments, and the file system by every name it accepts for the file. So a page a production server refuses - the VS Viewer's - was served when its path was written with an encoded letter (/%69iziVSViewer.html), a path parameter (/iiziVSViewer.html;x=1), a dot segment (/./iiziVSViewer.html) and, on a file system that takes them for the same file, in another case, with a trailing dot or by its short name (/IIZIVSVIEWER.HTML, /iiziVSViewer.html., /IIZIVS~1.HTM); and iiziApp.html went out as the file lies on disk, without what the server adds to it (measured on a production and a development server at r21997).

The one target. Every such rule compares the target this class derives, once per request:

  1. normalize(String): the path decoded, its path parameters dropped, its . and .. segments resolved and repeated slashes taken as one - the path by which the web server finds a file;
  2. onDisk(String), where a rule guards a file of the web root: when the normalized path names an existing file or directory of the web root, the path by the names the file system itself holds for it. Whether another case of the letters, a trailing dot or a short name reaches the same file is decided by the file system of the web root, for that file, and by nothing else: on a file system that honors case, another case names no file and the target stays as it was written, which the web server then does not find either.
A target that names no file - the JSON pages below /iizi/, a WebSocket - has no other name on disk and is compared as normalized, in its own case: that is how the web server's own mapping finds it.

What is remembered. Asking the file system for the names of a file costs a few hundred microseconds on Windows (every name from the drive down is read), on every request for a file of the web root. So an instance (forRoot(String)) remembers the paths that WERE a file's own names, and answers them without asking again. Only that answer is remembered: another name of a file is asked of the file system every time, so nothing remembered can make a rule miss - a path remembered as its own name names that file or, once the file is gone, nothing the web server finds. (A file renamed in the case of its letters only, while the server runs, keeps its old name here until the restart.)

Jetty itself answers the ambiguous spellings with status 400 before any of this runs (//, an encoded . segment, an encoded /; its default URI compliance).

Author:
Christopher Mindus
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the targets of a web root: created once, when a server starts.
    static String
    Normalizes the path of a request: decoded, path parameters dropped, . and .. segments resolved, repeated slashes as one (org.eclipse.jetty.util.URIUtil).
    of(String path)
    Gets the target of a request for a rule that guards a file of the web root: normalize(String), then onDisk(String).
    static String
    of(Path root, String path)
    Gets the target of a request as of(String), asking the file system at every call.
    onDisk(String target)
    Gets a normalized target by the names the file system holds, as onDisk(Path,String) does, without asking the file system again for a path that was a file's own name.
    static String
    onDisk(Path root, String target)
    Gets the target by the names the file system holds: when the normalized target names an existing file or directory of the web root, its path below the root as the file system spells it - so that /IIZIVSVIEWER.HTML, /iiziVSViewer.html. and a short name are /iiziVSViewer.html where the file system finds that file by them, and stay what they are where it does not.
    static Path
    root(String root)
    Gets the real path of a web root for onDisk(Path,String).
  • Method Details

    • forRoot

      public static RequestTarget forRoot(String root)
      Gets the targets of a web root: created once, when a server starts.
      Parameters:
      root - The web root, null for none: a target is then its normalized path.
      Returns:
      The instance.
    • of

      public String of(String path)
      Gets the target of a request for a rule that guards a file of the web root: normalize(String), then onDisk(String).
      Parameters:
      path - The path as the client wrote it, without the query; null for none.
      Returns:
      The target, empty for none.
    • onDisk

      public String onDisk(String target)
      Gets a normalized target by the names the file system holds, as onDisk(Path,String) does, without asking the file system again for a path that was a file's own name.
      Parameters:
      target - The normalized target (normalize(String)).
      Returns:
      The target of the file found; else the target unchanged.
    • normalize

      public static String normalize(String path)
      Normalizes the path of a request: decoded, path parameters dropped, . and .. segments resolved, repeated slashes as one (org.eclipse.jetty.util.URIUtil). The case of the letters is kept. A path that cannot be decoded, or whose dot segments leave the root, keeps that step as it was written: the web server refuses such a request itself.

      The path is decoded ONCE: never hand this method a path that is already decoded.

      Parameters:
      path - The path as the client wrote it, without the query; null for none.
      Returns:
      The normalized path, empty for none.
    • root

      public static Path root(String root)
      Gets the real path of a web root for onDisk(Path,String).
      Parameters:
      root - The web root.
      Returns:
      The root by the names the file system holds for it; its absolute path when it cannot be resolved, null for no root.
    • onDisk

      public static String onDisk(Path root, String target)
      Gets the target by the names the file system holds: when the normalized target names an existing file or directory of the web root, its path below the root as the file system spells it - so that /IIZIVSVIEWER.HTML, /iiziVSViewer.html. and a short name are /iiziVSViewer.html where the file system finds that file by them, and stay what they are where it does not. Links are not followed: a link is a file of its own name. The file system is asked at every call.
      Parameters:
      root - The real path of the web root (root(String)), null for none.
      target - The normalized target (normalize(String)).
      Returns:
      The target of the file found, with / between its names; else the target unchanged: no file of that name, a name the file system does not accept, a file outside the root.
    • of

      public static String of(Path root, String path)
      Gets the target of a request as of(String), asking the file system at every call.
      Parameters:
      root - The real path of the web root (root(String)), null for none.
      path - The path as the client wrote it, without the query; null for none.
      Returns:
      The target, empty for none.