Skip to content

HTTParty response cache is broken #764

@seanneale

Description

@seanneale

Rails 6.0.5.1
Ruby 2.7.6

We have recently upgraded HTTParty to v0.20.0 and found that the cached response is missing some information from the response.request:

  • last_uri
  • raw_request
  • last_response

We require raw_request for our logging, so have reverted to v0.19.1

Scripts to reproduce the issue:

  1. Script closer to the root cause
url = "https://avatars.githubusercontent.com/u/12815721?s=200&v=4"
r = HTTParty.get(url);nil
r.request.raw_body
# => nil
Marshal.load(Marshal.dump(r)).request.raw_body
# expected: nil
# actual: NoMethodError (undefined method `body' for nil:NilClass)
  1. Script closer to our scenario
# Enable cache in the local
make bash-devel
rails dev:cache
bin/rails c

url = "https://avatars.githubusercontent.com/u/12815721?s=200&v=4"

# set cache
r_2 = Rails.cache.fetch("sean_test", expires_in: 5.minutes, race_condition_ttl: 5, force: true) do
  r = HTTParty.get(url)
end

# test if body available (it will be)
r_2.request.raw_body

# fetch cache
r_2_cache = Rails.cache.fetch("sean_test", expires_in: 5.minutes, race_condition_ttl: 5) do
  HTTParty.get(url)
end; nil

# test if body available (it won't be)
r_2_cache.request.raw_body

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions