fix: allow stream protocols to return headers with multiple values (#14887)
* fix: allow stream protocols to return headers with multiple values This allows stream protocols to return headers with multiple values as an array of values. Fixes https://github.com/electron/electron/issues/14778 * Prefer ConvertFromV8 * Cleanup header conversion 1. Deduplicate the code by using a lambda 2. Remove duplicate calls to headers->Get(key) * Fix broken test Headers with multiple values are now being converted correctly, this test asserted the wrong behavior.
This commit is contained in:
parent
6fa940f2c1
commit
3b6f0d83e1
2 changed files with 63 additions and 12 deletions
|
@ -529,7 +529,7 @@ describe('protocol module', () => {
|
|||
cache: false,
|
||||
success: (data, _, request) => {
|
||||
assert.strictEqual(request.status, 200)
|
||||
assert.strictEqual(request.getResponseHeader('x-electron'), 'a,b')
|
||||
assert.strictEqual(request.getResponseHeader('x-electron'), 'a, b')
|
||||
assert.strictEqual(data, text)
|
||||
done()
|
||||
},
|
||||
|
@ -589,6 +589,36 @@ describe('protocol module', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('returns response multiple response headers with the same name', (done) => {
|
||||
const handler = (request, callback) => {
|
||||
callback({
|
||||
headers: {
|
||||
'header1': ['value1', 'value2'],
|
||||
'header2': 'value3'
|
||||
},
|
||||
data: getStream()
|
||||
})
|
||||
}
|
||||
|
||||
protocol.registerStreamProtocol(protocolName, handler, (error) => {
|
||||
if (error) return done(error)
|
||||
$.ajax({
|
||||
url: protocolName + '://fake-host',
|
||||
cache: false,
|
||||
success: (data, status, request) => {
|
||||
// SUBTLE: when the response headers have multiple values it
|
||||
// separates values by ", ". When the response headers are incorrectly
|
||||
// converting an array to a string it separates values by ",".
|
||||
assert.strictEqual(request.getAllResponseHeaders(), 'header1: value1, value2\r\nheader2: value3\r\n')
|
||||
done()
|
||||
},
|
||||
error: (xhr, errorType, error) => {
|
||||
done(error || new Error(`Request failed: ${xhr.status}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('protocol.isProtocolHandled', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue