Skip to content

Commit

Permalink
Merge pull request #549 from erickoledadevrel/master
Browse files Browse the repository at this point in the history
Fix for issue #548 - Batch requests fail if the response contains duplicate HTTP headers
  • Loading branch information
peleyal committed Jun 10, 2015
2 parents d78d382 + 9e7219c commit e8992a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Src/GoogleApis.Tests/Apis/Requests/BatchRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class BatchMessageHandler : CountableMessageHandler
ETag: ""\""10011\""""
Content-Type: application/json; charset=UTF-8
Content-Length: 505
Vary: Accept-Encoding
Vary: Referer
{
""etag_key"": ""\""10011\"""",
Expand Down Expand Up @@ -301,6 +303,8 @@ void SubtestExecuteAsync_Test(bool successful2ndReponse)
var httpMessage = tuple.Item3; // HTTP message
Assert.That(httpMessage.Content.Headers.ContentType.MediaType, Is.EqualTo("application/json"));
Assert.That(httpMessage.Content.Headers.ContentLength, Is.EqualTo(505));
Assert.True(httpMessage.Headers.Vary.Contains("Accept-Encoding"));
Assert.True(httpMessage.Headers.Vary.Contains("Referer"));

tuple = responses[1];
if (successful2ndReponse)
Expand Down
11 changes: 9 additions & 2 deletions Src/GoogleApis/Apis/Requests/BatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,15 @@ internal static HttpResponseMessage ParseAsHttpResponse(string content)
while (!string.IsNullOrEmpty((line = reader.ReadLine())))
{
var separatorIndex = line.IndexOf(':');
headersDic.Add(line.Substring(0, separatorIndex).Trim(),
line.Substring(separatorIndex + 1).Trim());
var key = line.Substring(0, separatorIndex).Trim();
var value = line.Substring(separatorIndex + 1).Trim();
// Check if the header already exists, and if so append its value
// to the existing value. Fixes issue #548.
if (headersDic.ContainsKey(key)) {
headersDic[key] = headersDic[key] + ", " + value;
} else {
headersDic.Add(key, value);
}
}

// Set the content.
Expand Down

0 comments on commit e8992a4

Please sign in to comment.