Skip to content

Commit dc89cfd

Browse files
committed
refactor: reuse unsafe header regex pattern
1 parent 10ee0c4 commit dc89cfd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/eventsource.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var lineFeed = 10
1616
var carriageReturn = 13
1717
// Beyond 256KB we could not observe any gain in performance
1818
var maxBufferAheadAllocation = 1024 * 256
19+
// Headers matching the pattern should be removed when redirecting to different origin
20+
var reUnsafeHeader = /^(cookie|authorization)$/i
1921

2022
function hasBom (buf) {
2123
return bom.every(function (charCode, index) {
@@ -482,7 +484,7 @@ function MessageEvent (type, eventInitDict) {
482484
function removeUnsafeHeaders (headers) {
483485
var safe = {}
484486
for (var key in headers) {
485-
if (/^(cookie|authorization)$/i.test(key)) {
487+
if (reUnsafeHeader.test(key)) {
486488
continue
487489
}
488490

0 commit comments

Comments
 (0)