rest-client-components icon indicating copy to clipboard operation
rest-client-components copied to clipboard

rest-client response.cookies fails when rack cache enabled

Open dazza-codes opened this issue 10 years ago • 3 comments

See https://github.com/rest-client/rest-client/issues/411

dazza-codes avatar Aug 10 '15 19:08 dazza-codes

Transferring content on this issue here.

dazza-codes avatar Sep 06 '15 14:09 dazza-codes

The exception is

NoMethodError: undefined method `url' for #<RestClient::Rack::Compatibility:0x007fdc16559b10>
from /home/dlweber/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:52:in `block in cookie_jar'

e.g.

> client = {:clientId=>"dms", :clientSecret=>"dms-annos"};
> tc.auth
=> #<RestClient::Resource:0x00000006018438
 @block=nil,
 @options={:cookies=>{}, :headers=>{:accept=>"application/ld+json", :content_type=>"application/ld+json"}, :open_timeout=>5, :read_timeout=>30},
 @url="https://triannon-dev.stanford.edu/auth">
> json_payloads = { accept: :json, content_type: :json };
> response = tc.auth["/client_identity"].post client.to_json, json_payloads;
> response.is_a? RestClient::Response
=> true
> response.headers
=> {:x_frame_options=>"SAMEORIGIN",
 :x_xss_protection=>"1; mode=block",
 :x_content_type_options=>"nosniff",
 :content_type=>"application/json; charset=utf-8",
 :etag=>"W/\"e9767a04a1db0d9b828970d126ab512d\"",
 :cache_control=>"max-age=0, private, must-revalidate",
 :x_request_id=>"7913b771-bfba-4870-871d-35d31224e959",
 :x_runtime=>"0.169223",
 :server=>"WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)",
 :date=>"Mon, 10 Aug 2015 18:37:24 GMT",
 :content_length=>"186",
 :connection=>"Keep-Alive",
 :set_cookie=>
  ["[\"request_method=POST; path=/\", \"_internal_session=QmFic2VmUEE5QTRoUTM1YzNaaXc4NVE1bVFaS3pOeS93VWtPYy9VWWF2b2tGcXlDRVZabUZzMEU5MisrdmVHS2RCR2JUK3FuZXNHWDZBbmtDR21xRUM0RldRYU1nd3pQTEQ3MUNUaVg5UDM4dVdnTy9LL2RSWTRaaFg2YitTMjNPRkpsZUpUY2ZCaFN3VkZkUkNEZWI5TUxDSzNYcUdNbTFJYWprSEdRdnFLVFcxKzFVc3BjTUtuU3QrbHFXS1N0cjV3ZllCVys5SWFjVFRjNUIvc0hlUHJiUUtHSU9qK096TXdUSk96NWJWNEJrSzQra2trakNSVjBHWmV4Ym1mWU15SFBYbmt5MURwT25Sc0VqYkswREd1WDB6K3IrS2Q2YlRuVXpiZk1IK3Rza0twSFRFWXIzWU41NkVZbWJWM0ZPRXZhajU1WklhUmkzeTlONUlPVEJ2QmsyRk5FTldiK3ljOGx6azJua0FNajJCc3I4YzVOZ09mUVVjckF1M255VHBTMU4yZ2owaE5ldzMzSnAzWFFzUHBCSnlZcXdPMlZHVTB3czVncFhyRXFIdDlhT3ZZUWhxWStoM2FVaTd3anhrUWJQRWQ4WWg5ZVRXcWQ0NnhlWXlZUnNvNHVWMjA0akJjQi83ZWhVSkU9LS0rWDEvRjFLbWFueks1SCt2WlNFcHBRPT0%3D--db491117968003865a0fa7679429f8e2fd9b282b; path=/; HttpOnly\"]"],
 :x_rack_cache=>"invalidate, pass"}

> response.cookies
NoMethodError: undefined method `url' for #<RestClient::Rack::Compatibility:0x007fdc16559b10>
from /home/dlweber/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:52:in `block in cookie_jar'

> response.request.class
=> RestClient::Rack::Compatibility

The gem bundle includes:

/home/snip/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rack-1.6.4
/home/snip/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rack-cache-1.2
/home/snip/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0
/home/snip/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rest-client-components-1.4.0

dazza-codes avatar Sep 06 '15 14:09 dazza-codes

WRT rest-client it looks like request.response.url is accessed while parsing cookies at:

  • https://github.com/rest-client/rest-client/blob/master/lib/restclient/abstract_response.rb#L63
  • Although the current master branch may not be the same as the 1.8.0 release.

Somehow, the rest-client-component replaces this instance of @response with an instance of RestClient::Rack::Compatibility. My guess is that this occurs in:

  • https://github.com/crohr/rest-client-components/blob/master/lib/restclient/components.rb#L13-L19
  • https://github.com/crohr/rest-client-components/blob/master/lib/restclient/components.rb#L169-L186

Maybe @gkellogg can shed some light on why this doesn't support the response.url method (in the context of parsing cookies)? A quick search for 'cookies' in the components.rb code doesn't find anything.

dazza-codes avatar Sep 06 '15 14:09 dazza-codes