Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed HTTP Header 'host' parameter parsing #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

itsjunetime
Copy link

Since HTTP header fields are case-insensitive (see here), we have to check for both Host and host for the http host header. This checks for the existence of host: if Host: returns nothing.

@@ -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`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will solve that case, but what if somebody decides to go with more creative approaches. HosT, aso. We should compare it lowercased. But that is for the future. This should solve immediate issues

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about converting data to a string, setting it all to lowercase, and then checking for host: against that? Do you think that would be a better long-term solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants