Skip to main content
Changed to HEAD request, match case-insensitive, use CRLF instead of LF to end lines.
Source Link
wobtax
  • 1.2k
  • 3
  • 17

Using GNU awkAWK (HTTP only):

echo 'http://bitly.is/urlshortening' |
  awk ''BEGIN{
        ORS="\r\n"   # end printed lines with CRLF
        IGNORECASE=1 # header names vary in capitalization
       }
  (gsub(/^http:\/\//,"")==0){ print "unable to use " $0; next }                                                                                                   
  { domain = gensub(/\/.*$/,"","g")   # e.g. bitly.is
    path = gensub(/^[^/]*\//,"/","g") # e.g. /urlshortening
    http_connection = "/inet/tcp/0/" domain "/80"
    print "GET"HEAD " path " HTTP/1.1" |& http_connection
    print "Host: " domain |& http_connection
    print "Connection: close\n\n"close\n" |& http_connection
    while ((http_connection |& getline) > 0)
      if(gsub(/^Location: /,"") > 0)
        print
  }'

This submits a GETHEAD request based on. I got the templateidea from this question on CodeGolf: https://codegolf.stackexchange.com/questions/61836/the-worlds-smallest-web-browser

This only works for link shortening services that support just HTTP (but I checked, and both bitly.is and tinyurl allow it!). There's probably a way to do HTTPS too (use /443 and...encrypt it somehow), but my knowledge doesn't go that far.

Using GNU awk (HTTP only):

echo 'http://bitly.is/urlshortening' |
  awk '(gsub(/^http:\/\//,"")==0){ print "unable to use " $0; next }                                                                                                   
  { domain = gensub(/\/.*$/,"","g")   # e.g. bitly.is
    path = gensub(/^[^/]*\//,"/","g") # e.g. /urlshortening
    http_connection = "/inet/tcp/0/" domain "/80"
    print "GET " path " HTTP/1.1" |& http_connection
    print "Host: " domain |& http_connection
    print "Connection: close\n\n" |& http_connection
    while ((http_connection |& getline) > 0)
      if(gsub(/^Location: /,"") > 0)
        print
  }'

This submits a GET request based on the template from this question on CodeGolf: https://codegolf.stackexchange.com/questions/61836/the-worlds-smallest-web-browser

This only works for link shortening services that support just HTTP (but I checked, and both bitly.is and tinyurl allow it!). There's probably a way to do HTTPS too (use /443 and...encrypt it somehow), but my knowledge doesn't go that far.

Using GNU AWK (HTTP only):

echo 'http://bitly.is/urlshortening' |
  awk 'BEGIN{
        ORS="\r\n"   # end printed lines with CRLF
        IGNORECASE=1 # header names vary in capitalization
       }
  (gsub(/^http:\/\//,"")==0){ print "unable to use " $0; next }                                                                                                   
  { domain = gensub(/\/.*$/,"","g")   # e.g. bitly.is
    path = gensub(/^[^/]*\//,"/","g") # e.g. /urlshortening
    http_connection = "/inet/tcp/0/" domain "/80"
    print "HEAD " path " HTTP/1.1" |& http_connection
    print "Host: " domain |& http_connection
    print "Connection: close\n" |& http_connection
    while ((http_connection |& getline) > 0)
      if(gsub(/^Location: /,"") > 0)
        print
  }'

This submits a HEAD request. I got the idea from this question on CodeGolf: https://codegolf.stackexchange.com/questions/61836/the-worlds-smallest-web-browser

This only works for link shortening services that support just HTTP (but I checked, and both bitly.is and tinyurl allow it!). There's probably a way to do HTTPS too (use /443 and...encrypt it somehow), but my knowledge doesn't go that far.

Source Link
wobtax
  • 1.2k
  • 3
  • 17

Using GNU awk (HTTP only):

echo 'http://bitly.is/urlshortening' |
  awk '(gsub(/^http:\/\//,"")==0){ print "unable to use " $0; next }                                                                                                   
  { domain = gensub(/\/.*$/,"","g")   # e.g. bitly.is
    path = gensub(/^[^/]*\//,"/","g") # e.g. /urlshortening
    http_connection = "/inet/tcp/0/" domain "/80"
    print "GET " path " HTTP/1.1" |& http_connection
    print "Host: " domain |& http_connection
    print "Connection: close\n\n" |& http_connection
    while ((http_connection |& getline) > 0)
      if(gsub(/^Location: /,"") > 0)
        print
  }'

This submits a GET request based on the template from this question on CodeGolf: https://codegolf.stackexchange.com/questions/61836/the-worlds-smallest-web-browser

This only works for link shortening services that support just HTTP (but I checked, and both bitly.is and tinyurl allow it!). There's probably a way to do HTTPS too (use /443 and...encrypt it somehow), but my knowledge doesn't go that far.