unjs / httpxy

🔀 A Full-Featured HTTP and WebSocket Proxy for Node.js
Other
194 stars 12 forks source link

Relative URL for Location response header causes TypeError (e.g. 201 Created) #20

Open xelaris opened 1 year ago

xelaris commented 1 year ago

Environment

httpxy 0.1.5 node 20 (but doesn't really matter)

Reproduction

not needed, I think

Describe the bug

If the server responds with a relativ URL in the Location header (e.g. in case of 201 Created), it causes an "Uncaught TypeError: Invalid URL" error, since there is no second parameter to the URL constructor in: https://github.com/unjs/httpxy/blob/1f62fffb141e905a398f55eb34bd75366082ca3c/src/middleware/web-outgoing.ts#L38

For example:

HTTP/1.1 201 Created
Location: /api/books/1

Additional context

The Location response header is allowed to contain a relativ URL, according to: https://www.rfc-editor.org/rfc/rfc9110#field.location

The URL constructor needs a base argument in that case: https://nodejs.org/api/url.html#new-urlinput-base

Logs

No response