Send `X-Metro-Delta-ID` header

Summary:
Adds additional headers to delta responses:
- The next delta ID. This helps to defer parsing the delta payload to a different layer.
- The size of the delta. This can be used as a hint for memory allocation

Reviewed By: jeanlauliac

Differential Revision: D7428603

fbshipit-source-id: 1d5e840991ec8cb490d33b3bc97444b0d7a3a0f3
This commit is contained in:
David Aurelio 2018-03-29 09:07:52 -07:00 committed by Facebook Github Bot
parent a15a515f37
commit 01599ed55e
2 changed files with 10 additions and 5 deletions

View File

@ -433,6 +433,8 @@ describe('processRequest', () => {
], ],
reset: true, reset: true,
}); });
expect(response.headers['X-Metro-Delta-ID']).toEqual('XXXXX-0');
}); });
it('should generate an incremental delta correctly', async () => { it('should generate an incremental delta correctly', async () => {
@ -469,6 +471,8 @@ describe('processRequest', () => {
reset: false, reset: false,
}); });
expect(response.headers['X-Metro-Delta-ID']).toEqual('XXXXX-1');
expect(DeltaBundler.prototype.getDelta.mock.calls[0][1]).toEqual({ expect(DeltaBundler.prototype.getDelta.mock.calls[0][1]).toEqual({
reset: false, reset: false,
}); });

View File

@ -84,6 +84,7 @@ function debounceAndBatch(fn, delay) {
}; };
} }
const DELTA_ID_HEADER = 'X-Metro-Delta-ID';
const FILES_CHANGED_COUNT_HEADER = 'X-Metro-Files-Changed-Count'; const FILES_CHANGED_COUNT_HEADER = 'X-Metro-Files-Changed-Count';
class Server { class Server {
@ -687,12 +688,11 @@ class Server {
}), }),
); );
let output; let output, sequenceId;
try { try {
const {delta, graph, prepend, sequenceId} = await this._getDeltaInfo( let delta, graph, prepend;
options, ({delta, graph, prepend, sequenceId} = await this._getDeltaInfo(options));
);
output = { output = {
bundle: deltaJSBundle( bundle: deltaJSBundle(
@ -724,7 +724,8 @@ class Server {
} }
mres.setHeader(FILES_CHANGED_COUNT_HEADER, String(output.numModifiedFiles)); mres.setHeader(FILES_CHANGED_COUNT_HEADER, String(output.numModifiedFiles));
mres.setHeader('Content-Type', 'application/javascript'); mres.setHeader(DELTA_ID_HEADER, String(sequenceId));
mres.setHeader('Content-Type', 'application/json');
mres.setHeader('Content-Length', String(Buffer.byteLength(output.bundle))); mres.setHeader('Content-Length', String(Buffer.byteLength(output.bundle)));
mres.end(output.bundle); mres.end(output.bundle);