Skip to content

inspector: fix absolute URLs in network http#62955

Open
GrinZero wants to merge 1 commit intonodejs:mainfrom
GrinZero:fix/inspector-network-http-preview
Open

inspector: fix absolute URLs in network http#62955
GrinZero wants to merge 1 commit intonodejs:mainfrom
GrinZero:fix/inspector-network-http-preview

Conversation

@GrinZero
Copy link
Copy Markdown

@GrinZero GrinZero commented Apr 25, 2026

Summary

This PR fixes incorrect URL reporting in the HTTP network inspector when a client passes an absolute URL as options.path.

Before this change, the inspector always constructed the request URL as:

request.protocol + '//' + host + request.path

That works for normal relative paths such as /hello-world, but it breaks when request.path already contains a full URL, producing values like:

http://127.0.0.1:3000http://127.0.0.1:3000/hello-world

As a result, DevTools shows an incorrect Request URL in Network.requestWillBeSent and Network.responseReceived.

Problem

Observed behavior:

request.path shape Previous inspector URL Expected URL
/hello-world http://127.0.0.1:3000/hello-world http://127.0.0.1:3000/hello-world
http://127.0.0.1:3000/hello-world http://127.0.0.1:3000http://127.0.0.1:3000/hello-world http://127.0.0.1:3000/hello-world

This was reproducible with HTTP clients that forward an absolute URL through the path field.

Solution

The fix keeps the existing behavior for relative paths and adds a guard for absolute URL paths.

Behavior after this change:

  • If request.path starts with http:// or https://, use it directly.
  • Otherwise, keep constructing the URL from protocol, host, and path.

This keeps the patch small and isolates it from the compressed-response work, which will be handled separately.

Tests

The existing HTTP inspector test was extended to cover:

  • relative-path GET
  • absolute-URL-path GET
  • absolute-URL-path POST

The POST case also verifies that Network.getResponseBody() still returns the expected payload.

Some HTTP clients send an absolute URL in request.path. The network\ninspection code always prefixed request.protocol and host,\nwhich produced duplicated URLs such as\nhttp://hosthttp://host/path in Network.requestWillBeSent and\nNetwork.responseReceived.\n\nHandle absolute URL paths directly and keep the existing\nrelative-path behavior unchanged.\n\nExtend the HTTP inspector test to cover both GET and POST\nrequests that use an absolute URL as options.path and verify\nthat getResponseBody still returns the expected payload.\n\nSigned-off-by: GrinZero <[email protected]>
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/inspector

@nodejs-github-bot nodejs-github-bot added inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. labels Apr 25, 2026
@GrinZero
Copy link
Copy Markdown
Author

E2E:

const axios = require('axios')
const Koa = require('koa')
const Router = require('koa-router')

const app = new Koa()
const router = new Router()

router.get('/', async (ctx) => {
  const res = await axios.get('https://jsonplaceholder.typicode.com/posts')
  ctx.body = res.data
})

app.use(router.routes())
app.listen(3000)
  • before:
image
  • after:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants