https://github.com/silverwind/url-from-req
Reconstruct the original URL from a HTTP/1 or HTTP/2 request
https://github.com/silverwind/url-from-req
forwarded http http2 node proxy typescript url
Last synced: about 1 month ago
JSON representation
Reconstruct the original URL from a HTTP/1 or HTTP/2 request
- Host: GitHub
- URL: https://github.com/silverwind/url-from-req
- Owner: silverwind
- License: bsd-2-clause
- Created: 2026-03-18T19:05:38.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-04-10T00:36:03.000Z (2 months ago)
- Last Synced: 2026-04-10T02:40:50.132Z (2 months ago)
- Topics: forwarded, http, http2, node, proxy, typescript, url
- Language: TypeScript
- Size: 164 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# url-from-req
[](https://www.npmjs.org/package/url-from-req) [](https://www.npmjs.org/package/url-from-req) [](https://packagephobia.com/result?p=url-from-req) [](https://depx.co/pkg/url-from-req)
Returns a [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) object from a Node.js `IncomingMessage` or `Http2ServerRequest`, accounting for proxy headers.
## Features
- Works with HTTP/1.1, HTTPS, and HTTP/2
- Supports `Forwarded` (RFC 7239), `X-Forwarded-Proto`, `X-Forwarded-Host`, `X-Forwarded-Port`
- Zero dependencies
## Usage
```ts
import http from "node:http";
import http2 from "node:http2";
import {urlFromReq} from "url-from-req";
http.createServer((req, res) => {
res.end(urlFromReq(req).href); // "http://example.com/path?q=1"
}).listen(3000);
http2.createSecureServer({key, cert}, (req, res) => {
res.end(urlFromReq(req).href); // "https://example.com/path?q=1"
}).listen(3001);
```
## License
BSD-2-Clause