fix(proxy): propagate origin status code and handle 304 correctly#2197
Conversation
…mp version to 2.1.2
Fetch chapters from API if available, otherwise use initial data.
…ndling Restored verbose logging and implemented robust internal redirect following with infinite loop protection. Verified via web debugger.
There was a problem hiding this comment.
@K1ngfish3r mismatch between ArrayBufferLike (which includes SharedArrayBuffer). Try this:
const compressedBuffer = Buffer.concat(chunks);
if (compressedBuffer.length > 0) {
let decompressedBuffer: Buffer;
if (contentEncoding.includes('br')) {
decompressedBuffer = brotliDecompressSync(compressedBuffer) as Buffer;
} else if (contentEncoding.includes('gzip')) {
decompressedBuffer = gunzipSync(compressedBuffer) as Buffer;
} else if (contentEncoding.includes('zstd')) {
decompressedBuffer = zstdDecompressSync(compressedBuffer) as Buffer;
} else {
decompressedBuffer = compressedBuffer;
}
res.write(decompressedBuffer);
}
K1ngfish3r
left a comment
There was a problem hiding this comment.
run prettier here too
| key !== 'content-encoding' && | ||
| key !== 'content-length' |
There was a problem hiding this comment.
any reason why these two keys were specified here?
There was a problem hiding this comment.
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.
K1ngfish3r
left a comment
There was a problem hiding this comment.
this fixes covers on a few sources
…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
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
200and failing to propagate the actual status from the target server. When a server returned304 Not Modified(with an empty body), the proxy would still send200but with the empty body. The plugin, expecting valid JSON for a200response, would then fail with a JSON parsing error.Fix
res.statusCode = 200.proxyResevent handler.304responses to simply end the response without attempting to process a body.Verification
Verified using the Web Debugger with the NovelBuddy plugin. Subsequent "Fetch" requests that return
304now correctly trigger the browser's cache usage instead of causing JSON parsing errors in the plugin.