Skip to content

Commit

Permalink
[HttpWebRequest] Ignore Transfer-Encoding when there's no content.
Browse files Browse the repository at this point in the history
	If the transfer encoding was set to chunked, we tried to read even when
	the response might known to have no content. This led to timeouts.

	Fixes bug #686371.
  • Loading branch information
gonzalop committed Apr 9, 2011
1 parent 0dd62ba commit 11cee69
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mcs/class/System/System.Net/WebConnection.cs
Expand Up @@ -466,9 +466,12 @@ static void ReadDone (IAsyncResult result)
cnc.position = 0;

WebConnectionStream stream = new WebConnectionStream (cnc);
bool expect_content = ExpectContent (data.StatusCode, data.request.Method);
string tencoding = null;
if (expect_content)
tencoding = data.Headers ["Transfer-Encoding"];

string contentType = data.Headers ["Transfer-Encoding"];
cnc.chunkedRead = (contentType != null && contentType.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
cnc.chunkedRead = (tencoding != null && tencoding.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
if (!cnc.chunkedRead) {
stream.ReadBuffer = cnc.buffer;
stream.ReadBufferOffset = pos;
Expand All @@ -493,14 +496,16 @@ static void ReadDone (IAsyncResult result)

data.stream = stream;

if (!ExpectContent (data.StatusCode) || data.request.Method == "HEAD")
if (!expect_content)
stream.ForceCompletion ();

data.request.SetResponseData (data);
}

static bool ExpectContent (int statusCode)
static bool ExpectContent (int statusCode, string method)
{
if (method == "HEAD")
return false;
return (statusCode >= 200 && statusCode != 204 && statusCode != 304);
}

Expand Down

0 comments on commit 11cee69

Please sign in to comment.