Bug 50587 - AndroidClientHandler.AllowAutoRedirect = false : makes HTTPS requests fail as no body returned
Summary: AndroidClientHandler.AllowAutoRedirect = false : makes HTTPS requests fail as...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2016-12-21 16:02 UTC by Jamie Lord
Modified: 2017-03-13 13:55 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
AndroidClientHandler.AllowAutoRedirect bug example project (22.79 KB, application/x-zip-compressed)
2017-01-10 13:33 UTC, Jamie Lord
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jamie Lord 2016-12-21 16:02:43 UTC
Using the AndroidClientHandler and setting AllowAutoRedirect to false when making a HTTPS POST using .SendAsync results in the header information being omitted and thus a failed request/incorrect response from the server.
Comment 1 Jamie Lord 2016-12-21 16:26:34 UTC
Why has this been marked as spam? It is a reproducible issue that myself and the team I work with believe is a genuine bug.
Comment 2 Jamie Lord 2017-01-03 10:26:03 UTC
Possibly related to/was found with https://bugzilla.xamarin.com/show_bug.cgi?id=51182
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2017-01-03 16:40:09 UTC
(Side note for the spam marking: Apologies for the incorrect spam marking, and many thanks for resetting the bug to the proper location.  The spam marking in this case was from a manual filtering step by some of the Xamarin team members, so once in a while an extra bug accidentally gets checked off from the incoming bug list that is not in fact spam.  I have usually reviewed the spam list and caught those mis-marked bugs within a half a day or so, but you were quick enough in resetting this one that you beat me to it.  Thanks again for correcting that!)
Comment 4 Marek Habersack 2017-01-10 11:55:10 UTC
@Jamie, can you provide a small app which reproduces the issue you're seeing?
Comment 5 Jamie Lord 2017-01-10 11:59:18 UTC
This appears to be an issue related to another problem with our code, it has been fixed when this issue was resolved: https://bugzilla.xamarin.com/show_bug.cgi?id=51182#c2
Comment 6 Jamie Lord 2017-01-10 12:02:39 UTC
Actually, scrap my previous comment, it is a valid issue.
Comment 7 Marek Habersack 2017-01-10 12:07:35 UTC
A repro would still be great :)
Comment 8 Jamie Lord 2017-01-10 13:33:19 UTC
Created attachment 19147 [details]
AndroidClientHandler.AllowAutoRedirect bug example project

In it's current state, the response.Content will contain a value.

If line 19 is uncommented then it will state that the post request has succeeded but Content will be null.

This is reproducible with any request to any server I can find.
Comment 9 chorsfield 2017-01-16 23:55:44 UTC
We are hitting this issue in Xamarin for AndroidClientHandler.AllowAutoRedirect = False

All responses (Success cases) Have null header and content. 

The Xamarin code here is at fault this always is true when AllowAutoRedirect  is false

bool HandleRedirect (HttpStatusCode redirectCode, HttpURLConnection httpConnection, RequestRedirectionState redirectState, out bool disposeRet)
		{
			if (!AllowAutoRedirect) {
				disposeRet = false;
				return true; // We shouldn't follow and there's no data to fetch, just return
			}
			disposeRet = true;



Then in DoProcessRequest this code returns right away after calling HandleRedirect (...)

This results in the Header, Content and Cookies been skipped on success calls whenever AllowAutoRedirect is false.


Seems like this Handler is not usable when AllowAutoRedirect is false.
Comment 10 Marek Habersack 2017-03-13 13:19:30 UTC
PR opened https://github.com/xamarin/xamarin-android/pull/481
Comment 11 Marek Habersack 2017-03-13 13:55:28 UTC
Fixed in

   xamarin-android/master, commit 1877806ab98c34298cf261980da76c10d5fb75d8
   monodroid/master, commit b55fa603b6e7049d95cdbc9c100b66d6d7d6d3c9