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

caching 404 status code responses breaks default RestClient behavior #16

Open
carlost opened this issue May 15, 2018 · 0 comments
Open

Comments

@carlost
Copy link

carlost commented May 15, 2018

404s are cacheable and some systems respond with cache friendly response headers. A public site that responds with cache 404s is https://www.theonion.com/.

RestClient raises an exception when a request results in a 404 response. Unfortunately, cached 404 responses break this behavior.

  • uncached requests that result in 404s will raise a RestClient exceptions: RestClient::NotFound: 404 Not Found
  • cached requests that result in 404s return an instance ofRestClient::Response

Using

  • ruby 2.5.1
  • rack-cache (1.7.1)
  • rest-client (2.0.2)
  • rest-client-components (1.5.0)

to recreate:

require 'restclient'
require 'restclient/exceptions'
require 'restclient/components'
require 'rack/cache'

RestClient.enable Rack::Cache

begin
  # this should throw a RestClient exception
  RestClient.get('https://www.theonion.com/tag/askdfkasdj')
  raise 'I guess we did not get an exception from the 404'
rescue RestClient::ResourceNotFound => e
  puts 'the first request raised a 404 exception'
end

response = RestClient.get('https://www.theonion.com/tag/askdfkasdj')

puts 'the second request did not raise a 404 exception'
puts "second response was of type: #{response.class}"
puts "second response code: #{response.code}"
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

1 participant