Skip to content

Commit

Permalink
Add Content-Length header to *.bundle responses
Browse files Browse the repository at this point in the history
Summary:
The main goal of this is to be able to show bundle download progress in a follow up PR for react-native.

**Test plan**
Tested that it is possible to show bundle download progress in react-native using this header and added unit test.
Closes #28

Reviewed By: davidaurelio

Differential Revision: D5443344

Pulled By: jeanlauliac

fbshipit-source-id: 63fd655c964d7df526125fbe55eb9c7cccd7dba9
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Jul 21, 2017
1 parent 3cc83da commit 16bb557
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/metro-bundler/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ describe('processRequest', () => {
});
});

it('returns Content-Length header on request of *.bundle', () => {
return makeRequest(
requestHandler,
'mybundle.bundle?runModule=true'
).then(response => {
expect(response.getHeader('Content-Length'))
.toBe(Buffer.byteLength(response.body));
});
});

it('returns 304 on request of *.bundle when if-none-match equals the ETag', () => {
return makeRequest(
requestHandler,
Expand Down
1 change: 1 addition & 0 deletions packages/metro-bundler/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ class Server {
mres.writeHead(304);
mres.end();
} else {
mres.setHeader('Content-Length', Buffer.byteLength(bundleSource));
mres.end(bundleSource);
}
debug('Finished response');
Expand Down

0 comments on commit 16bb557

Please sign in to comment.