Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8272758

HttpServer.createContext with a context path without trailing '/' should have '/' added implicitly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • None

      The current behavior (clarified in https://bugs.openjdk.java.net/browse/JDK-8225479) is contexts can be created without a trailing slash. This can lead to surprising behavior where for example a context of /foo will match /foobar.

      8225479 decided to just document it, but it seems safer to change the behavior to something less surprising.

      The proposal is to silently add a '/' to any context path that doesn't already have one at each time of use. It probably makes sense to record the context exactly as the caller specified it (with or without the '/') and return the same path from HttpContext.getPath. Otherwise, that could result in surprising behavior after the change (getPath() returning a different path to the one specified).

      The reason for silently adding the '/' is to support the most likely misuse of the current behavior ie registering /foo while intending the behavior of /foo/

      This will break other less likely misuses such as /foobar, which currently do work

            vyazici Volkan Yazici
            michaelm Michael McMahon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: