Browse files

Validate the content type of the bundle returned by the packager

When using the packager behind something like an http tunnel it is possible something else than JS is returned, in that case throw an error instead of trying to parse it.

This is useful for Expo since the packager runs behind ngrok. This allows to intercept that error and show a more meaningful error message based on the ngrok response.

**Test plan**
Tested by changing the packager to return text/html content type and validate that the error shows up properly.
Also tested that it works when multipart response is disabled.

<img width="354" alt="screen shot 2017-07-19 at 8 01 58 pm" src="">
Closes #15112

Differential Revision: D5459395

Pulled By: shergin

fbshipit-source-id: aaea7ab2e1311ee8dc10feb579adf9b9701d8d4c
  • Loading branch information...
janicduplessis authored and facebook-github-bot committed Jul 20, 2017
1 parent b6454e9 commit 3ce36698de9d2afac5cdaf6250287884defcc6c0
Showing with 15 additions and 0 deletions.
  1. +15 −0 React/Base/
@@ -243,6 +243,21 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
onComplete(error, nil, 0);
// Validate that the packager actually returned javascript.
NSString *contentType = headers[@"Content-Type"];
if (![contentType isEqualToString:@"application/javascript"]) {
error = [NSError errorWithDomain:@"JSServer"
NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Expected JavaScript, but got content type '%@'.", contentType],
@"headers": headers,
@"data": data
onComplete(error, nil, 0);
onComplete(nil, data, data.length);

0 comments on commit 3ce3669

Please sign in to comment.