Fix the Origin: header used in WebSocket requests.

Summary:
RFC 6454 section 7 defines the Origin: header syntax, and it's a
scheme, host, and optional port, not a URL.

Section 6 defines serialization of the header, including omission of the
port.

Therefore, we need to omit the trailing slash in all cases, and omit
the port if it matches the default port for the protocol.
Closes https://github.com/facebook/react-native/pull/7920

Differential Revision: D3387619

fbshipit-source-id: 552756e63ad41463af357a5073fae56c96e58958
This commit is contained in:
Ewan Mellor 2016-06-03 15:07:10 -07:00 committed by Facebook Github Bot 8
parent 7028929d8f
commit 03512fb721
1 changed files with 7 additions and 3 deletions

View File

@ -1565,10 +1565,14 @@ static const size_t RCTSRFrameHeaderOverhead = 32;
scheme = @"http";
}
if (self.port) {
return [NSString stringWithFormat:@"%@://%@:%@/", scheme, self.host, self.port];
int defaultPort = ([scheme isEqualToString:@"https"] ? 443 :
[scheme isEqualToString:@"http"] ? 80 :
-1);
int port = self.port.intValue;
if (port > 0 && port != defaultPort) {
return [NSString stringWithFormat:@"%@://%@:%d", scheme, self.host, port];
} else {
return [NSString stringWithFormat:@"%@://%@/", scheme, self.host];
return [NSString stringWithFormat:@"%@://%@", scheme, self.host];
}
}