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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Understanding:
      Fix Understood

      Description

      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

        Attachments

          Activity

            People

            Assignee:
            jboes Julia Boes
            Reporter:
            michaelm Michael McMahon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: