Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsure how to set timeout for a get() request #50

Closed
klauern opened this issue Jul 30, 2010 · 2 comments
Closed

unsure how to set timeout for a get() request #50

klauern opened this issue Jul 30, 2010 · 2 comments

Comments

@klauern
Copy link

klauern commented Jul 30, 2010

I'm not sure where I can ask this question, so apologies if this clutters the issue list a bit.

Where/How can I set a timeout for a request? Given the below class, I thgouth I could put it in the options hash along with my :basic_auth settings, but that doesn't seem to affect how long it takes before timing out.

class MyRequest
  include HTTParty

  def initialize(u, p)
    @auth = {:username => u, :password => p}
  end

  def get(path)
    options = {:basic_auth => @auth, :timeout => 120000}  # I didn't know if it would be ms or seconds 
    self.class.get(path, options)
  end

end

Anyone know how to do this?

@sandro
Copy link
Collaborator

sandro commented Jul 30, 2010

Looks just fine. We just set the Net::HTTP open_timeout and read_timeout which is measured in seconds.

You can also set a global timeout for all requests

class MyRequest
  include HTTParty
  default_timeout 5
end

@joshdeford
Copy link

Global timeout works like a champ!

@ghost ghost deleted a comment Jul 16, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants