Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unshort-tracer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unshort-tracer

A simple library that let you unshort any url and trace all redirections

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by900%
Maintainers
1
Weekly downloads
 
Created
Source

unshort-tracer

What can do this library?

unshort-tracer is a simple, dependency-less, promise-based library that can follow HTTP redirects and trace where is the url redirecting to. The main function returns an array with all the url redirections. Being the first element on this array the url suplied to the function, and the last element the final url.

Installation

$ npm install unshort-tracer --save

Usage

Most simple use case would be unshorting an url and printing all the redirections:

var unshort = require('unshort-tracer')

unshort('http://bit.ly/2Os3Tiw')
.then(urls => {
    console.log(urls[0]) // http://bit.ly/2Os3Tiw
    
    console.log(urls) // [ 'http://bit.ly/2Os3Tiw', 'https://goo.gl/6cwyTp',
                      // 'http://google.es/', 'http://www.google.es/',
                      // 'https://www.google.es/?gws_rd=ssl' ]
                      
    console.log(urls.length-1) // https://www.google.es/?gws_rd=ssl
})

Options

We can supply options to the main function as second argument to modify the behaviour of the library.

var unshort = require('unshort-tracer') 

var options = {
    method: "HEAD", // Specify the HTTP method that will be used to make the HTTP request. Default: GET
    max_depth: 20, // Specify how many redirections are we going to follow. Default: disabled, follow all redirections
    headers: {'User-Agent': 'Mozilla/5.0'} // Specify the headers that we will be sending in our request, for example an User-Agent.
}

unshort('http://bit.ly/2Os3Tiw', options)
.then(processRedirections)

You can also use any of the options of the native http.request function, take a look at them here: https://nodejs.org/api/http.html#http_http_request_options_callback

Keywords

FAQs

Package last updated on 06 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc