Skip to content

Commit

Permalink
Merge pull request #111 from Youscribe/ios-response-headers-fix
Browse files Browse the repository at this point in the history
Fix user agent response header on ios
  • Loading branch information
anaisbetts committed Dec 15, 2014
2 parents 38af503 + 5e795b1 commit b966bf7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ModernHttpClient/iOS/NSUrlSessionHandler.cs
Expand Up @@ -37,7 +37,12 @@ public class NativeMessageHandler : HttpClientHandler
new Dictionary<NSUrlSessionTask, InflightOperation>();

readonly Dictionary<HttpRequestMessage, ProgressDelegate> registeredProgressCallbacks =
new Dictionary<HttpRequestMessage, ProgressDelegate>();
new Dictionary<HttpRequestMessage, ProgressDelegate>();

readonly Dictionary<string, string> headerSeparators =
new Dictionary<string, string>(){
{"User-Agent", " "}
};

readonly bool throwOnCaptiveNetwork;
readonly bool customSSLVerification;
Expand All @@ -51,6 +56,13 @@ public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerificati

this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;
this.customSSLVerification = customSSLVerification;
}

private string GetHeaderSeparator(string name)
{
if (headerSeparators.ContainsKey(name))
return headerSeparators[name];
return ",";
}

public void RegisterForProgress(HttpRequestMessage request, ProgressDelegate callback)
Expand Down Expand Up @@ -90,8 +102,8 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
AllowsCellularAccess = true,
Body = NSData.FromArray(ms.ToArray()),
CachePolicy = NSUrlRequestCachePolicy.UseProtocolCachePolicy,
Headers = headers.Aggregate(new NSMutableDictionary(), (acc, x) => {
acc.Add(new NSString(x.Key), new NSString(String.Join(",", x.Value)));
Headers = headers.Aggregate(new NSMutableDictionary(), (acc, x) => {
acc.Add(new NSString(x.Key), new NSString(String.Join(GetHeaderSeparator(x.Key), x.Value)));
return acc;
}),
HttpMethod = request.Method.ToString().ToUpperInvariant(),
Expand Down

0 comments on commit b966bf7

Please sign in to comment.