Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android] Follow redirections to relative URLs (#2390)
Fixes: #1923 Consider this code: var client = new HttpClient(new AndroidClientHandler()); var res = await client.GetStringAsync("https://nghttp2.org/httpbin/redirect-to?url=/httpbin/get"); Accessing `https://nghttp2.org/httpbin/redirect-to?url=/httpbin/get` results in an HTTP-302 (redirect) to the location `/httpbin/get`: $ curl -D - https://nghttp2.org/httpbin/redirect-to?url=/httpbin/get HTTP/2 302 date: Wed, 28 Nov 2018 20:52:01 GMT content-type: text/html; charset=utf-8 content-length: 0 location: /httpbin/get ... Expected behavior within Xamarin.Android is that this should work: the HTTP-302 should be followed, with `httpClient.GetStringAsync()` returning the contents of `https://nghttp2.org/httpbin/get`. What instead happens is that an exception is thrown: System.InvalidCastException: Unable to convert instance of type 'Java.Net.URLConnectionInvoker' to type 'Java.Net.HttpURLConnection' Oops. Update `AndroidClientHandler.HandleRedirect()` to improve its support for the `Location` header, such that if the `Location` header value contains a URL that is relative or lacks schema/host, we now use the original request URL to construct the destination URL. Additionally, if the original URL contains a fragment but the destination does not, we append the fragment to the destination.
- Loading branch information