Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(desktop): send the upload length through the app proxy (#3755)

Hampus01656a56e7ba
diff --git a/fluxer_desktop/src/main/DesktopSessionHTTP.ts b/fluxer_desktop/src/main/DesktopSessionHTTP.ts
index 6ab6e51cb..ceefdd65b 100644
--- a/fluxer_desktop/src/main/DesktopSessionHTTP.ts
+++ b/fluxer_desktop/src/main/DesktopSessionHTTP.ts
@@ -61,6 +61,10 @@ function isRefusedRequestHeader(name: string): boolean {
return CHROMIUM_REFUSED_REQUEST_HEADERS.has(normalized) || normalized.startsWith('proxy-');
}
+function declaresContentLength(headers: Readonly<Record<string, string>>): boolean {
+ return Object.keys(headers).some((name) => name.toLowerCase() === 'content-length');
+}
+
function decodedResponseHeaders(headers: Record<string, string | Array<string>>): http.IncomingHttpHeaders {
const result: http.IncomingHttpHeaders = {};
const decoded = headers['content-encoding'] != null;
@@ -183,7 +187,7 @@ export function sendThroughDesktopSession(request: DesktopSessionHTTPRequest): P
clientRequest.end(Buffer.from(requestBody));
return;
}
- clientRequest.chunkedEncoding = true;
+ clientRequest.chunkedEncoding = !declaresContentLength(request.headers);
requestBody.on('error', (error: Error) => {
clientRequest.abort();
fail(error);
diff --git a/fluxer_desktop/src/main/LocalAppProxyClient.ts b/fluxer_desktop/src/main/LocalAppProxyClient.ts
index df40fc9d8..1ffa01788 100644
--- a/fluxer_desktop/src/main/LocalAppProxyClient.ts
+++ b/fluxer_desktop/src/main/LocalAppProxyClient.ts
@@ -163,7 +163,7 @@ export class DesktopLocalAppProxyClient {
const outboundRequest: DesktopOutboundHTTPRequest = {
body: body == null ? null : instrumentedRequestBody(body, request),
expectedOrigin: target.origin,
- headers: outboundHeaders(request.headers, request.acceptEncoding),
+ headers: outboundHeaders(request.headers, request.acceptEncoding, body == null ? null : request.uploadTotalBytes),
maximumRequestBodyBytes: LOCAL_APP_PROXY_REQUEST_BODY_MAX_BYTES,
method: request.method,
originTrust: DesktopOriginTrust.REGISTERED,
@@ -209,7 +209,11 @@ export class DesktopLocalAppProxyClient {
}
}
-function outboundHeaders(headers: Headers, acceptEncoding: string | null): Record<string, string> {
+function outboundHeaders(
+ headers: Headers,
+ acceptEncoding: string | null,
+ contentLength: number | null,
+): Record<string, string> {
const values: Record<string, string> = Object.create(null) as Record<string, string>;
headers.forEach((value, name) => {
values[name] = value;
@@ -217,6 +221,9 @@ function outboundHeaders(headers: Headers, acceptEncoding: string | null): Recor
if (acceptEncoding != null) {
values['Accept-Encoding'] = acceptEncoding;
}
+ if (contentLength != null) {
+ values['Content-Length'] = contentLength.toString();
+ }
return values;
}