From a2a27614abbd1f5bb8d98d64cf41ce7c8b796bcc Mon Sep 17 00:00:00 2001 From: Maximillian Dornseif Date: Wed, 2 Oct 2013 23:16:53 +0200 Subject: [PATCH] Ensure only ASCII is used in the User-Agent header. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The charset for HTTP headers has to be ASCII at best and is ill defined at worst. My Applikation has a Bundle Name with Umlauts in it which results in bessy Webserver log files due to the "strange" engoding of the App name. To me it seems, that AFNetworking is meant to transcode the App name to ASCII but the implementation is lacking and thus only encodes to Latin1/ISO8859-1. This patch - although not tested with Asian scripts - should result in User-Agent strings always beeing ASCII while remaining mostly unchanged. So `Überland/0.16.27` becomes `Uberland/0.16.27` which is much more standards compliant. --- AFNetworking/AFURLRequestSerialization.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 983f0d8..5e231cf 100755 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -205,7 +205,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { if (userAgent) { if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) { NSMutableString *mutableUserAgent = [userAgent mutableCopy]; - CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, kCFStringTransformToLatin, false); + CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, CFSTR("Any-Latin; Latin-ASCII; [:^ASCII:] Remove"), false); userAgent = mutableUserAgent; } [self setValue:userAgent forHTTPHeaderField:@"User-Agent"];