local-ch / lhc

🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.
GNU General Public License v3.0
43 stars 1 forks source link

Default Timeout #111

Closed 10xSebastian closed 6 years ago

10xSebastian commented 6 years ago

MINOR VERSION

Timeout

Working and configuring timeouts is important, to ensure your app stays alive when services you depend on start to get really slow...

LHC forwards two timeout options directly to typhoeus:

timeout (in seconds) - Pass a long as parameter containing timeout - the maximum time in seconds that you allow the libcurl transfer operation to take. Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting perfectly normal operations. This option may cause libcurl to use the SIGALRM signal to timeout system calls. connecttimeout (in seconds) - Pass a long. It should contain the maximum time in seconds that you allow the connection phase to the server to take. This only limits the connection phase, it has no impact once it has connected. Set to zero to switch to the default built-in connection timeout - 300 seconds.

LHC.get('http://local.ch', timeout: 5, connecttimeout: 1)

LHC provides a timeout interceptor that let you apply default timeout values to all the requests that you are performig in your application.

Default Timeout Interceptor

Applies default timeout values to all requests made in an application, that uses LHC.

  LHC.config.interceptors = [LHC::DefaultTimeout]

timeout default: 15 seconds connecttimeout default: 1 second

Overwrite defaults

LHC::DefaultTimeout.timeout = 5 # seconds
LHC::DefaultTimeout.connecttimeout = 2 # second