Skip to content

fix(proxy): propagate origin status code and handle 304 correctly - #2197

Merged
K1ngfish3r merged 12 commits into
lnreader:masterfrom
7ui77:fix-proxy-status-propagation
May 19, 2026
Merged

fix(proxy): propagate origin status code and handle 304 correctly#2197
K1ngfish3r merged 12 commits into
lnreader:masterfrom
7ui77:fix-proxy-status-propagation

Conversation

@7ui77

Copy link
Copy Markdown
Contributor

This PR fixes a critical issue in the web debugger's proxy server that was causing 'Unexpected end of JSON input' errors when debugging plugins.

Issue

The proxy was hardcoding the response status code to 200 and failing to propagate the actual status from the target server. When a server returned 304 Not Modified (with an empty body), the proxy would still send 200 but with the empty body. The plugin, expecting valid JSON for a 200 response, would then fail with a JSON parsing error.

Fix

  • Removed hardcoded res.statusCode = 200.
  • Implemented status code propagation in the proxyRes event handler.
  • Added explicit handling for 304 responses to simply end the response without attempting to process a body.
  • Improved decompression handling for various encodings (Brotli, Gzip, Zstd).

Verification

Verified using the Web Debugger with the NovelBuddy plugin. Subsequent "Fetch" requests that return 304 now correctly trigger the browser's cache usage instead of causing JSON parsing errors in the plugin.

Comment threadproxy.ts
Comment threadproxy.ts Outdated
@7ui77
7ui77 marked this pull request as draft May 18, 2026 22:48
@7ui77
7ui77 marked this pull request as ready for review May 18, 2026 23:21

@7ui777ui77 left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@K1ngfish3r mismatch between ArrayBufferLike (which includes SharedArrayBuffer). Try this:

constcompressedBuffer=Buffer.concat(chunks);if(compressedBuffer.length>0){letdecompressedBuffer: Buffer;if(contentEncoding.includes('br')){decompressedBuffer=brotliDecompressSync(compressedBuffer)asBuffer;}elseif(contentEncoding.includes('gzip')){decompressedBuffer=gunzipSync(compressedBuffer)asBuffer;}elseif(contentEncoding.includes('zstd')){decompressedBuffer=zstdDecompressSync(compressedBuffer)asBuffer;}else{decompressedBuffer=compressedBuffer;}res.write(decompressedBuffer);}

@K1ngfish3rK1ngfish3r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run prettier here too

Comment threadproxy.ts Outdated
Comment threadproxy.ts
Comment on lines +247 to +248
key !== 'content-encoding' &&
key !== 'content-length'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why these two keys were specified here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client is now raw data. If you keep 'content-encoding: gzip', the browser will attempt to decompress it again, causing an error.
The data size after decompression will definitely change compared to the original. If you keep the old 'content-length', the browser will either freeze—waiting to receive the full original byte count—or throw an 'Unexpected end of data' error.

@7ui77
7ui77 requested a review from K1ngfish3rMay 19, 2026 04:42

@K1ngfish3rK1ngfish3r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes covers on a few sources

@K1ngfish3r
K1ngfish3r merged commit 86de999 into lnreader:masterMay 19, 2026
1 check passed
@7ui77
7ui77 deleted the fix-proxy-status-propagation branch May 19, 2026 09:39
nofzo pushed a commit to nofzo/lnreader-plugins that referenced this pull request May 22, 2026
…reader#2197)
* fix(novelbuddy): fix watermark regex and bump version to 2.1.2
* fix(novelbuddy): fix watermark regex, remove chapter api fetch and bump version to 2.1.2
* fix(proxy): propagate origin status code and handle 304 Not Modified correctly
* Add API call for fetching manga chapters
Fetch chapters from API if available, otherwise use initial data.
* revert(novelbuddy): revert novelbuddy to version 2.1.1 and simple watermark removal
* fix(proxy): improve redirect handling, status propagation, and 304 handling
Restored verbose logging and implemented robust internal redirect following with infinite loop protection. Verified via web debugger.
* fix: type errors for buffer and redact sensitive logs
* fix: replace any with strictly typed separate variables
* chore(proxy): revert log redaction and run prettier
@github-actionsgithub-actionsBot locked as resolved and limited conversation to collaborators Jul 22, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@7ui77@K1ngfish3r