Add Content-Length header to *.bundle responses

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 https://github.com/facebook/metro-bundler/pull/28

Reviewed By: davidaurelio

Differential Revision: D5443344

Pulled By: jeanlauliac

fbshipit-source-id: 63fd655c964d7df526125fbe55eb9c7cccd7dba9
This commit is contained in:
Janic Duplessis 2017-07-21 03:41:03 -07:00 committed by Facebook Github Bot
parent 3cc83da403
commit 16bb5571c6
2 changed files with 11 additions and 0 deletions

View File

@ -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,

View File

@ -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');