Giter VIP home page Giter VIP logo

3xx's Introduction

Tools to grab the Location header

I have to deal with lots of things that hide the actual URL from me. I have to grab some quarantined URL to get the real URL. All I want is the Location header:

$ 3xx http://www.some-filter-thing.com/?deadbeef
https://www.perl.com/

And, I have to do this in a variety of environments where different tools are avialable so I've done the same thing in different tools.

A little test program

There's a Mojolicious program that has four paths. Three of those redirect in this chain:

* http://127.0.0.1:3000/three
* http://127.0.0.1:3000/two
* http://127.0.0.1:3000/one
* http://127.0.0.1:3000/none

Start the app:

$ perl app.pl daemon
[Tue Mar 19 21:15:09 2019] [info] Listening at "http://*:3000"
Server available at http://127.0.0.1:3000

Now try it. Each prints the redirect chain. Standard output is the URLs and anything else is on standard error.

$ python3.7 python/3xx http://127.0.0.1:3000/three
http://127.0.0.1:3000/two
http://127.0.0.1:3000/one
http://127.0.0.1:3000/none

$ ruby ruby/3xx http://127.0.0.1:3000/two
http://127.0.0.1:3000/one
http://127.0.0.1:3000/none

$ perl5.28.0 perl/3xx http://127.0.0.1:3000/one
http://127.0.0.1:3000/none

Get the last one with tail:

$ python3.7 python/3xx http://127.0.0.1:3000/three | tail -1
http://127.0.0.1:3000/none

Exit codes

  • 0 - Found a Location header
  • 1 - The request was a success, but there was no Location header
  • 2 - The request was some sort of error
  • 255 - There was a program error

Why not use curl?

Sure, show me how. But it's not as simple as sending a head request and grabbing the Location header. Some servers won't respond to that and I still have to strip out the header name. I end up with a pipeline in an alias.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.