You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Ryan Stewart (JIRA)" <ji...@apache.org> on 2010/04/02 15:48:27 UTC

[jira] Created: (HTTPCLIENT-929) Request with two forward slashes for path fails

Request with two forward slashes for path fails
-----------------------------------------------

                 Key: HTTPCLIENT-929
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.0.1
            Reporter: Ryan Stewart


The following code demonstrates the problem:
{code}
        DefaultHttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet("http://www.google.com//"));
{code}

When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
{noformat}
[...]
Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
	... 31 more
Caused by: java.net.URISyntaxException: Expected authority at index 2: //
	at java.net.URI$Parser.fail(URI.java:2809)
	at java.net.URI$Parser.failExpecting(URI.java:2815)
	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
	at java.net.URI$Parser.parse(URI.java:3024)
	at java.net.URI.<init>(URI.java:578)
	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
	... 33 more
{noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Resolved: (HTTPCLIENT-929) Request with two forward slashes for path fails

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-929.
------------------------------------------

    Resolution: Fixed

Fixed in SVN trunk

http://svn.apache.org/viewvc?rev=930558&view=rev

I looked at #relativize method but felt it was an overkill. I opted for a simpler and likely faster custom routine. Please review.

Oleg

> Request with two forward slashes for path fails
> -----------------------------------------------
>
>                 Key: HTTPCLIENT-929
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>             Fix For: 4.1 Alpha2
>
>
> The following code demonstrates the problem:
>         DefaultHttpClient client = new DefaultHttpClient();
>         client.execute(new HttpGet("http://www.google.com//"));
> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
> [...]
> Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
> 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> 	... 31 more
> Caused by: java.net.URISyntaxException: Expected authority at index 2: //
> 	at java.net.URI$Parser.fail(URI.java:2809)
> 	at java.net.URI$Parser.failExpecting(URI.java:2815)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
> 	at java.net.URI$Parser.parse(URI.java:3024)
> 	at java.net.URI.<init>(URI.java:578)
> 	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
> 	... 33 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-929) Request with two forward slashes for path fails

Posted by "Ryan Stewart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12853213#action_12853213 ] 

Ryan Stewart commented on HTTPCLIENT-929:
-----------------------------------------

The change looks good. I built the latest SVN trunk, and it runs the test case above without problem.

> Request with two forward slashes for path fails
> -----------------------------------------------
>
>                 Key: HTTPCLIENT-929
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>             Fix For: 4.1 Alpha2
>
>
> The following code demonstrates the problem:
>         DefaultHttpClient client = new DefaultHttpClient();
>         client.execute(new HttpGet("http://www.google.com//"));
> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
> [...]
> Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
> 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> 	... 31 more
> Caused by: java.net.URISyntaxException: Expected authority at index 2: //
> 	at java.net.URI$Parser.fail(URI.java:2809)
> 	at java.net.URI$Parser.failExpecting(URI.java:2815)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
> 	at java.net.URI$Parser.parse(URI.java:3024)
> 	at java.net.URI.<init>(URI.java:578)
> 	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
> 	... 33 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Updated: (HTTPCLIENT-929) Request with two forward slashes for path fails

Posted by "Ryan Stewart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ryan Stewart updated HTTPCLIENT-929:
------------------------------------

    Description: 
The following code demonstrates the problem:
        DefaultHttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet("http://www.google.com//"));

When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:

[...]
Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
	... 31 more
Caused by: java.net.URISyntaxException: Expected authority at index 2: //
	at java.net.URI$Parser.fail(URI.java:2809)
	at java.net.URI$Parser.failExpecting(URI.java:2815)
	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
	at java.net.URI$Parser.parse(URI.java:3024)
	at java.net.URI.<init>(URI.java:578)
	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
	... 33 more


  was:
The following code demonstrates the problem:
{code}
        DefaultHttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet("http://www.google.com//"));
{code}

When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
{noformat}
[...]
Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
	... 31 more
Caused by: java.net.URISyntaxException: Expected authority at index 2: //
	at java.net.URI$Parser.fail(URI.java:2809)
	at java.net.URI$Parser.failExpecting(URI.java:2815)
	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
	at java.net.URI$Parser.parse(URI.java:3024)
	at java.net.URI.<init>(URI.java:578)
	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
	... 33 more
{noformat}


> Request with two forward slashes for path fails
> -----------------------------------------------
>
>                 Key: HTTPCLIENT-929
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>
> The following code demonstrates the problem:
>         DefaultHttpClient client = new DefaultHttpClient();
>         client.execute(new HttpGet("http://www.google.com//"));
> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
> [...]
> Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
> 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> 	... 31 more
> Caused by: java.net.URISyntaxException: Expected authority at index 2: //
> 	at java.net.URI$Parser.fail(URI.java:2809)
> 	at java.net.URI$Parser.failExpecting(URI.java:2815)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
> 	at java.net.URI$Parser.parse(URI.java:3024)
> 	at java.net.URI.<init>(URI.java:578)
> 	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
> 	... 33 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Updated: (HTTPCLIENT-929) Request with two forward slashes for path fails

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-929:
-----------------------------------------

    Fix Version/s: 4.1 Alpha2

> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). 
> I don't fully understand why this method does what it does

DefaultRequestDirector rewrites the request URI in order to comply with the requirements of the RFC 2626

---
5.1.2 Request-URI

...

   The most common form of Request-URI is that used to identify a
   resource on an origin server or gateway. In this case the absolute
   path of the URI MUST be transmitted (see section 3.2.1, abs_path) as
   the Request-URI, and the network location of the URI (authority) MUST
   be transmitted in a Host header field. For example, a client wishing
   to retrieve the resource above directly from the origin server would
   create a TCP connection to port 80 of the host "www.w3.org" and send
   the lines:

       GET /pub/WWW/TheProject.html HTTP/1.1
       Host: www.w3.org
---

The only thing that can be done about this problem is replacing multiple "/" in the abs_path with a single one.

Would that solve the problem for you?

Oleg

> Request with two forward slashes for path fails
> -----------------------------------------------
>
>                 Key: HTTPCLIENT-929
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>             Fix For: 4.1 Alpha2
>
>
> The following code demonstrates the problem:
>         DefaultHttpClient client = new DefaultHttpClient();
>         client.execute(new HttpGet("http://www.google.com//"));
> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
> [...]
> Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
> 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> 	... 31 more
> Caused by: java.net.URISyntaxException: Expected authority at index 2: //
> 	at java.net.URI$Parser.fail(URI.java:2809)
> 	at java.net.URI$Parser.failExpecting(URI.java:2815)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
> 	at java.net.URI$Parser.parse(URI.java:3024)
> 	at java.net.URI.<init>(URI.java:578)
> 	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
> 	... 33 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-929) Request with two forward slashes for path fails

Posted by "Ryan Stewart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12853069#action_12853069 ] 

Ryan Stewart commented on HTTPCLIENT-929:
-----------------------------------------

Yes, I think that's the right approach. The problem should only happen when the path is composed of nothing but two or more slashes, but it should also be safe to replace any series of multiple slashes with a single one. Alternately, while I was looking into it, I discovered that URI has a relativize method that works like so: 
        URI uri1 = URI.create("http://www.google.com/foo"); 
        URI uri2 = URI.create("http://www.google.com").relativize(uri1); 

Final content of uri2: path="foo". When you tell it to relativize "http://www.google.com//", you get an empty URI, which is accurate. Could you just use this instead of reconstructing the URI manually?

> Request with two forward slashes for path fails
> -----------------------------------------------
>
>                 Key: HTTPCLIENT-929
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-929
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>             Fix For: 4.1 Alpha2
>
>
> The following code demonstrates the problem:
>         DefaultHttpClient client = new DefaultHttpClient();
>         client.execute(new HttpGet("http://www.google.com//"));
> When a request is made, the DefaultRequestDirector invokes rewriteRequestURI(). I don't fully understand why this method does what it does. For a non-proxied request, it attempts to render the URI to a relative URI. In doing so, it tries to create a relative URI whose content is "//". Per RFC 2396 section 5 (Relative URI References), a relative URI that begins with "//" is a network-path reference, and the "//" must be immediately followed by an authority. Therefore, while "http://www.google.com//" is a valid absolute URI, "//" is not a valid relative one. The resulting exception:
> [...]
> Caused by: org.apache.http.ProtocolException: Invalid URI: http://www.google.com//
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:339)
> 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:434)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> 	... 31 more
> Caused by: java.net.URISyntaxException: Expected authority at index 2: //
> 	at java.net.URI$Parser.fail(URI.java:2809)
> 	at java.net.URI$Parser.failExpecting(URI.java:2815)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3063)
> 	at java.net.URI$Parser.parse(URI.java:3024)
> 	at java.net.URI.<init>(URI.java:578)
> 	at org.apache.http.client.utils.URIUtils.createURI(URIUtils.java:106)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:141)
> 	at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:159)
> 	at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:333)
> 	... 33 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org