Skip to content

Commit

Permalink
refactor: reuse unsafe header regex pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed May 12, 2022
1 parent 10ee0c4 commit dc89cfd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var lineFeed = 10
var carriageReturn = 13
// Beyond 256KB we could not observe any gain in performance
var maxBufferAheadAllocation = 1024 * 256
// Headers matching the pattern should be removed when redirecting to different origin
var reUnsafeHeader = /^(cookie|authorization)$/i

function hasBom (buf) {
return bom.every(function (charCode, index) {
Expand Down Expand Up @@ -482,7 +484,7 @@ function MessageEvent (type, eventInitDict) {
function removeUnsafeHeaders (headers) {
var safe = {}
for (var key in headers) {
if (/^(cookie|authorization)$/i.test(key)) {
if (reUnsafeHeader.test(key)) {
continue
}

Expand Down

0 comments on commit dc89cfd

Please sign in to comment.