Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-348

getRequestURI returns welcome file instead of original request

    XMLWordPrintable

Details

    Description

      Given a request to / and a welcome file set to /index

      JBossWeb wil return "/" when HttpServletRequest#getRequestURI is called,
      and "/index" when HttpServletRequest#getServletPath is called.

      Undertow will return "/index" in both cases.

      It's clear what happens by looking at ServletInitialHandler#handleRequest
      which does a full rewrite for welcome files:

      exchange.setRelativePath(exchange.getRelativePath() + info.getRewriteLocation());
      exchange.setRequestURI(exchange.getRequestURI() + info.getRewriteLocation());
      exchange.setRequestPath(exchange.getRequestPath() + info.getRewriteLocation());
      

      The Servlet spec (10.10) does seem to justify this somewhat by saying the
      following:

      The container may send the request to the welcome resource with a forward, a redirect, or a container specific mechanism that is indistinguishable from a direct request.

      However, the JavaDoc for HttpServletRequest#getRequestURI doesn't seem to allow this.

      Example:

      With a welcome file declaration in web.xml as follows:

      <welcome-file-list>
          <welcome-file>index</welcome-file>
      </welcome-file-list>
      

      and when requesting the context root of an application (e.g. http://localhost:8080 for a root deployment), the results are as follows:

        getRequestURI getServletPath
      Tomcat/JBossWeb / /welcome
      Undertow /welcome /welcome

      Attachments

        Activity

          People

            sdouglas1@redhat.com Stuart Douglas
            arjant_jira Arjan t (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: