Fix Content-Type header checking of React/RCTJavascriptLoader.mm #15791

Summary:
To fix this issue: https://github.com/facebook/react-native/issues/15791
Closes https://github.com/facebook/react-native/pull/15792

Differential Revision: D5813101

Pulled By: shergin

fbshipit-source-id: fd3eb6f1d9ccdeb5373d1ba2b2df173ff7a8e986
This commit is contained in:
Justin Reynolds 2017-09-19 19:45:52 -07:00 committed by Facebook Github Bot
parent 11963d824d
commit 3ae45d5cb8
1 changed files with 5 additions and 4 deletions

View File

@ -284,16 +284,17 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
// Validate that the packager actually returned javascript. // Validate that the packager actually returned javascript.
NSString *contentType = headers[@"Content-Type"]; NSString *contentType = headers[@"Content-Type"];
if (![contentType isEqualToString:@"application/javascript"] && NSString *mimeType = [[contentType componentsSeparatedByString:@";"] firstObject];
![contentType isEqualToString:@"text/javascript"]) { if (![mimeType isEqualToString:@"application/javascript"] &&
NSString *description = [NSString stringWithFormat:@"Expected Content-Type to be 'application/javascript' or 'text/javascript', but got '%@'.", contentType]; ![mimeType isEqualToString:@"text/javascript"]) {
NSString *description = [NSString stringWithFormat:@"Expected MIME-Type to be 'application/javascript' or 'text/javascript', but got '%@'.", mimeType];
error = [NSError errorWithDomain:@"JSServer" error = [NSError errorWithDomain:@"JSServer"
code:NSURLErrorCannotParseResponse code:NSURLErrorCannotParseResponse
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey: description, NSLocalizedDescriptionKey: description,
@"headers": headers, @"headers": headers,
@"data": data @"data": data
}]; }];
onComplete(error, nil); onComplete(error, nil);
return; return;
} }