saokar / urlrewritefilter

Automatically exported from code.google.com/p/urlrewritefilter
Other
0 stars 0 forks source link

<to encode="true"> should apply to forwards #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am rewriting URLs to images that have spaces in their names. Something like:

<rule>
    <from>^/img/(.*)$</from>
    <to>/images/$1</to>
</rule>

The images themselves are being served by the container (Tomcat 6). When
image names have spaces in them, Tomcat reports a 404 because the to URL is
not being encoded and has a space in the name.

Changing this to <to encode="true"> has no effect because
NormalRewrittenUrl.doRewrite() does not encode forwards, only redirects.

I believe this is a bug in NormalRewrittenUrl as these forwards will always
fail for URLs that require reencoding.

I looked in to writing a test for this but the 3.2.0 test suite is failing
for me on clean checkout and I didn't want to get in to figuring out what
was going on there.

Original issue reported on code.google.com by alon.car...@gmail.com on 27 May 2009 at 12:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I tried out this patch but it does not help for the following case:

<rule>
    <from>^/documents/(.*)$</from>
    <to type="forward" encode="true">/MyServlet/document=$1</to>
</rule>

I've added the following lines to the code the get more infos:

        if (isEncode()) {
          System.out.println("target before encode: " + target);
          target = hsResponse.encodeRedirectURL(target);
          System.out.println("target after encode: " + target);
        }

Using the Request URL: 
http://localhost:8080/documents/document%20with%20spaces.pdf
returns the following output:

target before encode: /MyServlet/document=document with spaces.pdf
target after encode: /MyServlet/document=document with spaces.pdf

but not 
target after encode: /MyServlet/document=document%20with%20spaces.pdf
or
target after encode: /MyServlet/document=document+with+spaces.pdf

kind regargds,
hasan

Original comment by hasan.ca...@gmail.com on 10 Aug 2009 at 12:40

GoogleCodeExporter commented 9 years ago
There seems to be a common misconception around the "encode" property in the 
<to>
section of the rule. Unlike the regular understanding, the implementation of 
this
property does not invoke java.net.URLEncoder#encode or any other known 
subclasses. It
rather encodes the session-id into URL's as described here -
http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletR
esponse.html#encodeURL(java.lang.String)

AFAIK, this is not doable without patching the Filter. There seems to be a valid
attempt made here - 
http://code.google.com/p/urlrewritefilter/issues/detail?id=27

Paul, can you please throw some light on this?

Original comment by avl...@gmail.com on 10 Aug 2009 at 3:47

GoogleCodeExporter commented 9 years ago
Merging this into issue 27
(http://code.google.com/p/urlrewritefilter/issues/detail?id=27). A fix will 
happen
against the same issue.

Original comment by avl...@gmail.com on 7 Jan 2010 at 5:04