Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions deps/dicer/lib/HeaderParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ HeaderParser.prototype.push = function (data) {
let end = data.length
let appendEnd = data.length
let found = false
let splitTail = 0
const tail = this.tail

for (let i = tail.length; i > 0; --i) {
Expand All @@ -40,6 +41,7 @@ HeaderParser.prototype.push = function (data) {
if (matched) {
end = S_DCRLF.length - i
appendEnd = 0
splitTail = i
found = true
break
}
Expand Down Expand Up @@ -74,6 +76,11 @@ HeaderParser.prototype.push = function (data) {
}

if (found) {
// A CRLFCRLF header terminator split across pushes left its leading bytes
// in this.buffer on the previous push; drop them so they do not trail the
// last header value. splitTail is 0 in the common case, making this a no-op.
this.buffer = this.buffer.slice(0, this.buffer.length - splitTail)
this.nread -= splitTail
this._finish()
return end
}
Expand Down
5 changes: 5 additions & 0 deletions test/dicer-headerparser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ test('dicer-headerparser', async t => {
expected: { foo: ['bar'] },
what: 'Header terminator across chunks'
},
{
source: ['Foo: bar\r', '\n\r\n'],
expected: { foo: ['bar'] },
what: 'Header terminator split between CR and LFCRLF leaves no trailing CR on the value'
},
{
source: ['Foo: bar\r', '\n\r', '\nextra'],
cfg: {
Expand Down
Loading