feat: Support response headers in File protocol handler (#16098)

* feat: Support response headers in File protocol handler

* bugfix: Null check headers value & fix tests

* refactor: Use non-deprecated FindKeyOfType
This commit is contained in:
David Baker 2018-12-19 06:17:02 +00:00 committed by Shelley Vohr
parent 03f876470e
commit cc85946f55
4 changed files with 44 additions and 10 deletions

View file

@ -320,6 +320,28 @@ describe('protocol module', () => {
})
})
it('sets custom headers', (done) => {
const handler = (request, callback) => callback({
path: filePath,
headers: { 'X-Great-Header': 'sogreat' }
})
protocol.registerFileProtocol(protocolName, handler, (error) => {
if (error) return done(error)
$.ajax({
url: protocolName + '://fake-host',
cache: false,
success: (data, status, request) => {
assert.strictEqual(data, String(fileContent))
assert.strictEqual(request.getResponseHeader('X-Great-Header'), 'sogreat')
done()
},
error: (xhr, errorType, error) => {
done(error)
}
})
})
})
it('sends object as response', (done) => {
const handler = (request, callback) => callback({ path: filePath })
protocol.registerFileProtocol(protocolName, handler, (error) => {