diff --git a/src/http.zig b/src/http.zig index d4f2c05d63..00cbf2f032 100644 --- a/src/http.zig +++ b/src/http.zig @@ -663,7 +663,7 @@ pub fn buildRequest(this: *HTTPClient, body_len: usize) picohttp.Request { if (body_len > 0 or this.method.hasRequestBody()) { if (this.flags.is_streaming_request_body) { - if (add_transfer_encoding) { + if (add_transfer_encoding and this.flags.upgrade_state == .none) { request_headers_buf[header_count] = chunked_encoded_header; header_count += 1; } diff --git a/src/http/HTTPThread.zig b/src/http/HTTPThread.zig index 8ed4f2f52a..d6946798e8 100644 --- a/src/http/HTTPThread.zig +++ b/src/http/HTTPThread.zig @@ -323,8 +323,8 @@ fn drainEvents(this: *@This()) void { if (client.state.original_request_body == .stream) { var stream = &client.state.original_request_body.stream; stream.ended = ended; - if (messageType == .endChunked) { - // only send the 0-length chunk if the request body is chunked + if (messageType == .endChunked and client.flags.upgrade_state != .upgraded) { + // only send the 0-length chunk if the request body is chunked and not upgraded client.writeToStream(is_tls, socket, bun.http.end_of_chunked_http1_1_encoding_response_body); } else { client.flushStream(is_tls, socket);