Skip to content

Commit

Permalink
fix(proxy): handle more content-disposition edge cases (#3100)
Browse files Browse the repository at this point in the history
<!-- Describe the problem and your solution --> 
Refactored the response handling to cover more edge cases. Instead of
checking if the `content-disposition` header is exactly equal to
`attachment`, we now check if it includes `attachment` or `inline`,
allowing for more flexibility. This change improves the handling of
different content types by considering both attachment and inline
dispositions.
<!-- Issue ticket number and link (if applicable) -->

<!-- Testing instructions (skip if just adding/editing providers) -->
Initially this was producing a malformed response with the dropbox and
front providers, but after the fix, it works as expected.

---------

Co-authored-by: Hassan Wari <[email protected]>
Co-authored-by: Khaliq <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent 5608eaa commit 564a703
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/server/lib/controllers/proxy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,17 @@ class ProxyController {
}
});

const contentType = responseStream.headers['content-type'];
const isJsonResponse = contentType && contentType.includes('application/json');
const isChunked = responseStream.headers['transfer-encoding'] === 'chunked';
const isEncoded = Boolean(responseStream.headers['content-encoding']);
const isAttachment = responseStream.headers['content-disposition'] === 'attachment';
const contentType = responseStream.headers['content-type'] || '';
const contentDisposition = responseStream.headers['content-disposition'] || '';
const transferEncoding = responseStream.headers['transfer-encoding'] || '';
const contentEncoding = responseStream.headers['content-encoding'] || '';

if (isChunked || isEncoded || isAttachment) {
const isJsonResponse = contentType.includes('application/json');
const isChunked = transferEncoding === 'chunked';
const isEncoded = Boolean(contentEncoding);
const isAttachmentOrInline = /^(attachment|inline)(;|\s|$)/i.test(contentDisposition);

if (isChunked || isEncoded || isAttachmentOrInline) {
const passThroughStream = new PassThrough();
responseStream.data.pipe(passThroughStream);
passThroughStream.pipe(res);
Expand Down

0 comments on commit 564a703

Please sign in to comment.