Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:12:04+00:00 2026-05-31T04:12:04+00:00

I made a handy little link expander using curl within my ruby (Sintra) app.

  • 0

I made a handy little link expander using curl within my ruby (Sintra) app.

  def curbexpand(link) 
    result = Curl::Easy.new(link)
    begin 
      result.headers["User-Agent"] = "..."
      result.verbose = true
      result.follow_location = true
      result.max_redirects = 3
      result.connect_timeout = 5
      result.perform
      return result.last_effective_url # Returns the final destination URL after x redirects...
    rescue
      return link
      puts "XXXXXXXXXXXXXXXXXXX Error parsing link XXXXXXXXXXXXXXXXXXXXXXXXXXX"
    end
  end

The problem I have is that some geniuses are using URL shorteners to link to .exe’s and .dmg’s which would be fine but it looks like my curl script above is waiting for the full response to be returned (i.e. it could be a 1GB file!) before returning the url. I don’t want to use third party link expander API’s as I have a significant volume of links to expand.

Anyone know how I can tweak curb to just find the url rather than waiting for the full response?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:12:05+00:00Added an answer on May 31, 2026 at 4:12 am

    I’ve done what you want using using Net::HTTP to process “HEAD” requests, and look for redirects that way. The advantage is a HEAD will not return content, only headers.

    From the docs:

    head(path, initheader = nil) 
    
    Gets only the header from path on the connected-to host. header is a Hash like { ‘Accept’ => ‘/’, … }.
    
    This method returns a Net::HTTPResponse object.
    
    This method never raises an exception.
    
    response = nil
    Net::HTTP.start('some.www.server', 80) {|http|
      response = http.head('/index.html')
    }
    p response['content-type']
    

    Combine that with the example in the Net::HTTP docs for following redirection, and you should be able to find your landing URL.

    You can probably use Curl::http_head to accomplish much the same thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a little afraid of using Wordpress because of his connotation all made, plus
Made this nice little loop for hiding and showing div's, works as a charm
My little site should be pooling list of items from a table using the
I'm writing my first gtk program, using gtkmm, and glade. I made a filechooserbutton
I have made a firefox extension which loads a web page using xmlhttprequest .
I'm just getting into Ruby - one of the things I'm having a little
I am developing an Android app for tablets and not using the compatibility library.
I have an application in which we use a hand-made build system.The reason for
I have a website built in PHP 4 with a framework made by hand
This is a second-hand question from an OS development site, but it made me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.