npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

original-url

v1.2.3

Published

Reconstruct the original URL used in an HTTP request based on the HTTP request headers

Downloads

1,264,171

Readme

original-url

Reconstruct the original URL used in an HTTP request based on the HTTP request headers.

The module takes into account potential URL rewrites made by proxies, load balancers, etc along the way (as long as these append special HTTP headers to the request).

Supported HTTP headers:

  • Host
  • Forwarded
  • X-Forwarded-Proto
  • X-Forwarded-Protocol
  • X-Url-Scheme
  • Front-End-Https
  • X-Forwarded-Ssl
  • X-Forwarded-Host
  • X-Forwarded-Port

If the protocol (http vs https) cannot be determined based on the above headers, the encrypted flag on the TLS connection is used.

npm Build status js-standard-style

Installation

npm install original-url --save

Usage

Server example:

const http = require('http')
const originalUrl = require('original-url')

const server = http.createServer(function (req, res) {
  const url = originalUrl(req)
  if (url.full) {
    res.end(`Original URL: ${url.full}\n`)
  } else {
    res.end('Original URL could not be determined\n')
  }
})

server.listen(1337)

Request examples:

$ curl localhost:1337
Original URL: http://localhost:1337/

$ curl -H 'Host: example.com' localhost:1337
Original URL: http://example.com/

$ curl -H 'Host: example.com:1234' localhost:1337
Original URL: http://example.com:1234/

$ curl -H 'Forwarded: proto=https; host=example.com; for="10.0.0.1:1234"' localhost:1337/sub/path?key=value
Original URL: https://example.com:1234/sub/path?key=value

$ curl -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Host: proxy.local' localhost:1337
Original URL: http://example.com/

API

result = originalUrl(req)

This module exposes a single function which takes an HTTP request object in the form of http.IncomingMessage.

When called, the function returns a result object with a full property containing the fully resolved URL. The result object will also contain any other property normally returned by the Node.js core url.parse function.

If the hostname for some reason cannot be determined, result.full will not be present.

License

MIT