Skip to content

fix(PP-3449): stop request inspector from swallowing proxied PUT/POST bodies - #190

Merged
sergak01 merged 1 commit into
developfrom
pp-3449-inspector-put-body-408
Jul 6, 2026
Merged

fix(PP-3449): stop request inspector from swallowing proxied PUT/POST bodies#190
sergak01 merged 1 commit into
developfrom
pp-3449-inspector-put-body-408

Conversation

@sergak01

@sergak01 sergak01 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔧 Fix: Request Inspector swallowing proxied PUT/POST bodies (408 Request Timeout)

Summary

Since the Request Inspector landed (e53fa90), PUT/POST requests with a body that go through the dev-server proxy never delivered their body to the MI backend. Apache waited for a body that never arrived and answered 408 Request Timeout. GET requests were unaffected, which made the failure look backend-side.

This PR fixes two independent defects introduced by the inspector wiring:

Key changes

  • src/plugin.ts 🔧 — the inspector's internal Express app (which globally applies express.json() / express.urlencoded()) was mounted for all paths before the proxy. The body parsers consumed the request stream, so http-proxy piped an already-exhausted stream to the backend. The app is now only routed requests for /@api/* and /@pp-dev/inspector — the same gate cli.ts (Next.js mode) already had.
  • src/lib/request-capture.middleware.ts 🔧 — capturing the request body via req.on('data') switched the stream into flowing mode; buffered chunks were emitted on process.nextTick, before the async proxy middleware attached its pipe, and were lost (this affected both Vite and Next.js modes). Capture now patches req.emit instead, observing chunks only when a downstream consumer actually reads the stream — stream state stays untouched.
  • tests/unit/lib/request-capture.middleware.spec.ts 🧪 — new regression suite: the middleware must not flip the stream into flowing mode, a late (next-tick) consumer must receive the full body, and the inspector must still capture bodies that are consumed downstream.

Testing

  • ✅ Unit: 188/188 (incl. 3 new regression tests), integration: 39/39, eslint clean
  • ✅ Local e2e repro (capture → gated internal server → http-proxy-middleware → Apache-like backend): pre-fix code reproduces the 408 Request Timeout page; fixed code returns 200 with all body bytes received
  • ✅ Live verification against stg7x.metricinsights.com via tests/test-commonjs: PUT with a JSON body answered by the MI app in 0.77 s (405 for a nonexistent path, as expected — no timeout), and the Inspector captured the request with its full 51-byte body (source: proxy)

Compatibility

No API or config changes; no breaking changes. Inspector UI/REST endpoints behave as before.

Included commits:

  • 610a993 fix(PP-3449): stop request inspector from swallowing proxied PUT/POST bodies

Merge Request: origin/pp-3449-inspector-put-body-408origin/develop

… bodies

The Request Inspector (added in e53fa90) broke request bodies for proxied
PUT/POST requests, causing the backend to answer 408 Request Timeout:

- plugin.ts mounted the inspector Express app (with global express.json/
  urlencoded body parsers) for all paths before the proxy, so JSON bodies
  were consumed before http-proxy could pipe them to the backend. Route
  only /@api/* and /@pp-dev/inspector into it, matching cli.ts.

- request-capture.middleware.ts attached a req 'data' listener, which
  switches the stream into flowing mode; buffered body chunks were emitted
  on process.nextTick, before the async proxy middleware attached its pipe,
  and were lost. Patch req.emit instead: chunks are observed only when a
  downstream consumer actually reads the stream, leaving its state intact.

Add regression tests covering stream neutrality, late (next-tick) consumers
receiving the full body, and capture still recording consumed bodies.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1eb4cf1-1ca7-475b-9682-370f0646e188

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pp-3449-inspector-put-body-408

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sergak01 sergak01 self-assigned this Jul 6, 2026
@sergak01
sergak01 merged commit 0323196 into develop Jul 6, 2026
3 checks passed
@sergak01
sergak01 deleted the pp-3449-inspector-put-body-408 branch July 6, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant