Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-9430

Allow rewriting outbound URLs

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • None
    • 5.1
    • Old Core
    • None
    • Unknown
    • N/A
    • N/A

    Description

      The urlrewritefilter library (http://www.tuckey.org/urlrewrite/) is a great tool for implementing short urls (as described on http://platform.xwiki.org/xwiki/bin/view/Main/ShortURLs). It supports both inbound URL rewriting and outbound rewriting. However in order for the outbound rule to work we need to call Response.encodeURL(), see http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletResponse.html#encodeURL(java.lang.String)

      I've tested it and it works if I modify XWikiServletURLFactory.createURL() by adding:

              URL result;
              try {
                  result = new URL(getServerURL(xwikidb, context), newpath.toString());
                  // For robust session tracking, all URLs emitted by a servlet should be encoded. Otherwise, URL rewriting
                  // cannot be used with browsers which do not support cookies.
                  String encodedURLAsString = context.getResponse().encodeURL(result.toExternalForm());
                  result = new URL(encodedURLAsString);
              } catch (MalformedURLException e) {
                  // This should not happen
                  result = null;
              }
      

      I hate the fact that we construct a URL, then serialize it to a String and then again reconstruct a URL but I don't see any way out of this.

      WDYT?

      Attachments

        Issue Links

          Activity

            People

              vmassol Vincent Massol
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: