Skip to content

Commit

Permalink
Fix http write (#3939)
Browse files Browse the repository at this point in the history
* Fix encoding problem when uploading a binary file.
Close: #3116

* use BufferList

* Finish rebase

---------

Co-authored-by: Hanaasagi <ambiguous404@gmail.com>
  • Loading branch information
paperclover and Hanaasagi authored Aug 3, 2023
1 parent aaaaf74 commit e83058c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/js/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ class ClientRequest extends OutgoingMessage {
#path;
#socketPath;

#body: string | null = null;
#bodyChunks: Buffer[] | null = null;
#fetchRequest;
#signal: AbortSignal | null = null;
[kAbortController]: AbortController | null = null;
Expand Down Expand Up @@ -1238,24 +1238,22 @@ class ClientRequest extends OutgoingMessage {
}

_write(chunk, encoding, callback) {
var body = this.#body;
if (!body) {
this.#body = chunk;
if (!this.#bodyChunks) {
this.#bodyChunks = [chunk];
callback();
return;
}
this.#body = body + chunk;
this.#bodyChunks.push(chunk);
callback();
}

_writev(chunks, callback) {
var body = this.#body;
if (!body) {
this.#body = chunks.join();
if (!this.#bodyChunks) {
this.#bodyChunks = chunks;
callback();
return;
}
this.#body = body + chunks.join();
this.#bodyChunks.push(...chunks);
callback();
}

Expand All @@ -1270,7 +1268,7 @@ class ClientRequest extends OutgoingMessage {
}

var method = this.#method,
body = this.#body;
body = Buffer.concat(this.#bodyChunks || []);

try {
this.#fetchRequest = fetch(
Expand Down
Loading

0 comments on commit e83058c

Please sign in to comment.