{"library":"original-url","title":"Reconstruct Original HTTP Request URL","description":"The `original-url` package provides a utility function to reconstruct the full, original URL of an HTTP request by intelligently parsing various standard and de-facto standard HTTP headers. It accounts for potential modifications made by proxies, load balancers, and other intermediaries by examining headers like `Host`, `Forwarded`, `X-Forwarded-Proto`, `X-Forwarded-Host`, `X-Forwarded-Port`, and others. If the protocol cannot be determined from headers, it leverages the TLS connection's `encrypted` flag. The module returns a URL object compatible with Node.js's native `url.parse` output, including a `full` property for the complete URL string. The current stable version is 1.2.3, published over 6 years ago, indicating a very mature or slow-moving project that is likely in maintenance mode rather than active development. Its primary differentiator is its comprehensive handling of various proxy-related headers to accurately determine the client-facing URL.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install original-url"],"cli":null},"imports":["import originalUrl from 'original-url';","const originalUrl = require('original-url');","const url = originalUrl(req); console.log(url.protocol, url.host, url.pathname, url.query, url.full);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import http from 'http';\nimport originalUrl from 'original-url';\n\nconst server = http.createServer(function (req, res) {\n  const url = originalUrl(req);\n  if (url.full) {\n    res.writeHead(200, { 'Content-Type': 'text/plain' });\n    res.end(`Original URL: ${url.full}\\nProtocol: ${url.protocol}\\nHost: ${url.host || 'N/A'}\\nPath: ${url.pathname || 'N/A'}\\nQuery: ${url.query || 'N/A'}\\n`);\n  } else {\n    res.writeHead(400, { 'Content-Type': 'text/plain' });\n    res.end('Original URL could not be determined. Check request headers.\\n');\n  }\n});\n\nserver.listen(1337, () => {\n  console.log('Server listening on http://localhost:1337');\n  console.log('Try with: curl localhost:1337');\n  console.log(\"Or with proxy headers: curl -H 'Forwarded: proto=https; host=example.com; for=\"10.0.0.1:1234\"' localhost:1337/sub/path?key=value\");\n});","lang":"javascript","description":"This example sets up a simple Node.js HTTP server that uses `original-url` to determine and display the original URL of incoming requests, including detailed URL components parsed from various proxy headers.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}