Skip to content

Commit

Permalink
change the state of the machine in case of trailing header (move to t…
Browse files Browse the repository at this point in the history
…he end instead of failing it)

Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Feb 3, 2025
1 parent 34e94d3 commit 057ec16
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/util/chunked_content_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ class ChunkedContentDecoder extends stream.Transform {
this.chunk_size = parseInt(header_items[0], 16);
if (!(this.chunk_size >= 0)) return this.error_state();
this.last_chunk = this.chunk_size === 0;
const header1 = header_items[1].split('=');
this.chunk_signature = header1[0] === 'chunk-signature' ? header1[1] : '';
if (header_items[1]) {
const header1 = header_items[1].split('=');
this.chunk_signature = header1[0] === 'chunk-signature' ? header1[1] : '';
}
this.chunk_header_str = '';
this.state = STATE_WAIT_NL_HEADER;
break;
Expand All @@ -73,15 +75,27 @@ class ChunkedContentDecoder extends stream.Transform {
if (content.length) this.push(content);
if (!this.chunk_size) this.state = STATE_WAIT_CR_DATA;
} else if (this.state === STATE_WAIT_CR_DATA) {
if (buf[index] !== CR_CODE) return this.error_state();
this.state = STATE_WAIT_NL_DATA;
if (buf[index] === CR_CODE) {
this.state = STATE_WAIT_NL_DATA;
} else {
// we might encounter trailer header printings
// at this point instead of return this.error_state()
// we would move the state-machine to STATE_CONTENT_END
this.state = STATE_CONTENT_END;
}
} else if (this.state === STATE_WAIT_NL_DATA) {
if (buf[index] !== NL_CODE) return this.error_state();
if (this.last_chunk) {
this.state = STATE_CONTENT_END;
} else {
this.state = STATE_READ_CHUNK_HEADER;
}
} else if (this.state === STATE_CONTENT_END) {
// TODO - handle trailers (HTTP headers)

// set the index to maximum (our way to skip)
// we should not push any content at this point!
index = buf.length - 1;
} else {
return this.error_state();
}
Expand Down

0 comments on commit 057ec16

Please sign in to comment.