From 78c467ed5ac6221823c73193faf057328a3137a7 Mon Sep 17 00:00:00 2001 From: iandwelker Date: Mon, 8 Feb 2021 15:44:16 -0700 Subject: [PATCH] Fixed HTTP Header 'host' parameter parsing --- Criollo/Source/HTTP/CRHTTPConnection.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Criollo/Source/HTTP/CRHTTPConnection.m b/Criollo/Source/HTTP/CRHTTPConnection.m index d0b87bf2..26319ddf 100644 --- a/Criollo/Source/HTTP/CRHTTPConnection.m +++ b/Criollo/Source/HTTP/CRHTTPConnection.m @@ -136,6 +136,10 @@ - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData*)data withTag:(long)ta CRHTTPVersion version = CRHTTPVersionMake(versionSpec); NSRange rangeOfHostHeader = [data rangeOfData:[@"Host: " dataUsingEncoding:NSUTF8StringEncoding] options:0 range:NSMakeRange(0, data.length)]; + + // Since HTTP header fields are case-insensitive (https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2), we have to check for both `Host` and `host`. + if ( rangeOfHostHeader.location == NSNotFound ) + rangeOfHostHeader = [data rangeOfData:[@"host: " dataUsingEncoding:NSUTF8StringEncoding] options:0 range:NSMakeRange(0, data.length)]; if ( rangeOfHostHeader.location != NSNotFound || version == CRHTTPVersion1_0 ) { NSString* hostSpec = @"localhost";