rlalfo / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

NullPointerException if redirect location is relative #80

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?
1.7.0-beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?
Java 6

Describe the problem.
Retrieving URL which redirects to local page using relative links leads to NPE
Example URL: http://vkontakte.ru/share.php?url=http://habr.ru/p/140827/
Code:
       HttpTransport transport = new NetHttpTransport();
        GenericUrl url = new GenericUrl("http://vkontakte.ru/share.php?url=http://habr.ru/p/140827/");
        HttpRequest request = transport.createRequestFactory().buildGetRequest(url);
        HttpResponse response = request.execute();
Exception:
Exception in thread "main" java.lang.NullPointerException
    at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:104)
    at com.google.api.client.http.HttpRequest.handleRedirect(HttpRequest.java:864)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:827)
    at Service.getPageContent(Service.java:64)

How would you expect it to be fixed?

I think redirect url should be constructed using current request

Original issue reported on code.google.com by esch...@gmail.com on 28 Mar 2012 at 7:23

GoogleCodeExporter commented 9 years ago
http://tools.ietf.org/html/rfc2616#section-14.30

According to the specification, the Location field points to an absolute URI, 
which indicates to me that a relative URL would be incompatible with the 
specification.

However, note this comment in wikipedia.org:

http://en.wikipedia.org/wiki/HTTP_location
http://en.wikipedia.org/wiki/URL_redirection#Using_server-side_scripting_for_red
irection

"While the internet standard RFC 1945 (HTTP 1.0) requires a complete absolute 
URI for redirection,[2][3] the most popular web browsers tolerate the passing 
of a relative URL as the value for a Location header.[citation needed]"

I tried it in Chrome and it works there.  So it seems reasonable to try to 
tolerate it in the client library as well.

Original comment by yan...@google.com on 23 Apr 2012 at 11:28

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 24 Oct 2012 at 5:39

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 13 Dec 2012 at 2:38

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 9 Jan 2013 at 8:50

GoogleCodeExporter commented 9 years ago
https://codereview.appspot.com/7058067/

Original comment by yan...@google.com on 9 Jan 2013 at 10:08

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 14 Jan 2013 at 8:08

GoogleCodeExporter commented 9 years ago
The fix cannot handle relative path redirect for empty path URL, @see 
http://code.google.com/p/google-http-java-client/issues/detail?id=201

Original comment by mingfai...@gmail.com on 23 Feb 2013 at 10:53

GoogleCodeExporter commented 9 years ago
Issue 198 has been merged into this issue.

Original comment by yan...@google.com on 11 Mar 2013 at 11:58