lhc

🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.

GPL-3.0 License

Downloads
255.6K
Stars
43
Committers
14

Bot releases are visible (Hide)

lhc -

Published by 10xSebastian over 4 years ago

Fixes the gemspec license version as mentioned in https://github.com/local-ch/lhc/issues/176

lhc -

Published by 10xSebastian over 4 years ago

lhc -

Published by 10xSebastian over 4 years ago

ignored_errors and error_handler have been for a long time being the only option applied to LHC requests which were not following the general, verb-kind-a wording that we use for all the other options and methods, like .get, cache:, retry:, followlocation``auth etc.

This PR renames the ignored_errors: option to ignore: and the error_handler option to rescue.

I tried to use handle instead of rescue but handle seems to be a ruby internal that we cannot use.

Migration Guide

  • rename all ignored_errors to ignore in your entire project
  • rename all error_handler to rescue in your entire project
lhc -

Published by 10xSebastian over 4 years ago

We discovered a bug in LHS where including resources that can not be found wouldn't work as expected.

This is a first improvement (minor) to solve the overall issue.

It allows to pass single keys to ignored_errors e.g.:

LHC.get('https://local.ch', ignored_errors: LHC::NotFound)
lhc -

Published by 10xSebastian over 4 years ago

When this feature was introduced, there was only 1 bearer token format, the one from auth.local.ch.

Now with Salesforce we have a second bearer token issuer, and this PR weakens the criterias under which a reauthenticate? is performed to refresh client tokens.

lhc -

Published by 10xSebastian over 4 years ago

This Version adds the form format, which allows to make easy application/x-www-form-urlencoded requests with an urlencoded body.

lhc -

Published by 10xSebastian over 4 years ago

Fixes the Status 0 (timeout) issues, by not using Typhoeus::Hydra memoization any longer.

lhc -

Published by 10xSebastian almost 5 years ago

The setting of the registering is not atomic, so it could happen that on start up, the registered flag is not yet set when a second thread initialises the Prometheus interceptor again. Simply adding a rescue for this case prevents an exception.

This should be idiomatic anyway.

lhc -

Published by 10xSebastian almost 5 years ago

Up to now, the timings from the prometheus monitoring were not very useful. They were using a key that is not following conventions and also using milliseconds with histogram buckets that only go up to 10. Meaning every request that takes longer than 10ms was not even monitored any more.

This follows the convention for histograms more closely and also adds the host label, so we can determine which requests are actually slow instead of guessing.

Also we now use a single key, lhc_requests and lhc_request_seconds, and differentiate the event using a label. This allows us to create a board that shows all of the LHC requests over several apps.

lhc -

Published by dimameshcharakou almost 5 years ago

lhc -

Published by skaestle about 5 years ago

PATCH

#165

This release improves on the Rollbar interceptor. Up until now it was possible to loose Rollbar messages when they caused a Encoding::UndefinedConversionError.

Now it will:

  1. rescue possible Encoding::UndefinedConversionError during Rollbar.warn
  2. attempt to fix the issue by calling fix_invalid_encoding on the values
  3. send the fixed data

For this to work easily we introduced:

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_transform_values.rb

into our codebase

lhc -

Published by skaestle about 5 years ago

PATCH

This release makes the necessary changes to be ready for Rails 6 and takes care of some annoying deprecation warnings. It also introduces explicit rspec runs for Rails 4 / 5 / 6

PR

https://github.com/local-ch/lhc/pull/163

lhc -

Published by 10xSebastian about 5 years ago

PATCH

This PR makes the retry interceptor consider to not retry a request if the error (response) was explicitly ignored. (Which was expected to work that way.)

Retry Interceptor

Do not retry certain response codes

If you do not want to retry based on certain response codes, use retry in combination with explicit ignore_errors:

  LHC.get('http://local.ch', ignore_errors: [LHC::NotFound], retry: { max: 1 })

Or if you use LHC::Retry.all:

LHC.get('http://local.ch', ignore_errors: [LHC::NotFound])
lhc -

Published by 10xSebastian about 5 years ago

Introduces a more generic test helper to require within your application when using LHC.

It also introduces a test to actually test Throttling track to be reset between tests.

lhc -

Published by 10xSebastian about 5 years ago

Having throttling expire is kind of necessary, that's also why this PR is patching the version.

Otherwise, as soon as the throttling interceptor hits the break, he will never get out of the break state again, as no further request would be allowed, which would update the current quota.

lhc -

Published by 10xSebastian about 5 years ago

fixes the case where tracked remaining was nil, and throttling break threw an exception.

lhc -

Published by 10xSebastian about 5 years ago

Was throwing exception when response had no headers set. Now does not raise any more.

lhc -

Published by 10xSebastian over 5 years ago

Throttle

The throttle interceptor allows you to raise an exception if a predefined quota of an provider request limit is reached in advance.

  LHC.configure do |c|
    c.interceptors = [LHC::Throttle]
  end
options = { 
  throttle: {
    track: true, # enables tracking of current limit/remaining requests of rate-limiting
    break: '80%', # quota in percent after which errors are raised
    provider: 'local.ch', # name of the provider under which throttling tracking is aggregated,
    limit: { header: 'Rate-Limit-Limit' }, # either a hard-coded integer, or a hash pointing at the response header containing the limit value
    remaining: { header: 'Rate-Limit-Remaining' }, # a hash pointing at the response header containing the current amount of remaining requests
  } 
}

LHC.get('http://local.ch', options)
# { headers: { 'Rate-Limit-Limit' => 100, 'Rate-Limit-Remaining' => 19 } }

LHC.get('http://local.ch', options)
# raises LHC::Throttle::OutOfQuota: Reached predefined quota for local.ch
lhc -

Published by 10xSebastian over 5 years ago

Retry all requests

If you want to retry all requests made from your application, you just need to configure it globally:

  LHC::Retry.all = true
  configuration.interceptors = [LHC::Retry]

In case this causes retried requests during your tests, tell your test suite to not retry requests during tests:

# spec/support/lhc.rb
LHC::Retry.all = false
lhc -

Published by 10xSebastian over 5 years ago

We get the following warnings a lot (unnecessarily)

[WARNING] Zipkin interceptor is enabled but dependencies are not found. See: https://github.com/local-ch/lhc#zipkin
This PR decouples tracing? (if tracing is happening) from dependencies? (which clearly just checks for dependencies.

So in your tests it would still complain if Zipkin has wrong dependencies (which might make your app crash when deployed), but it's not flooding you with warnings any longer, just because there is no current trace!