activeresource
activeresource copied to clipboard
Active Resource 6 breaking change: can't share common headers anymore
After PR #359 (I guess) has been merged, we can't define common headers on base classes and make them available to subclasses, as expected.
This way, each subclass must configure the same access token, for example, instead of using parent access token, which would not be very DRY.
Please take a look on following sample code (using fruits and apples just like ARes test cases).
# 5.1
fruit = Class.new(ActiveResource::Base)
apple = Class.new(fruit)
fruit.headers["key"] = "fruit-value"
fruit.headers # => {"key"=>"fruit-value"}
apple.headers # => {"key"=>"fruit-value"}
# 6.0
fruit = Class.new(ActiveResource::Base)
apple = Class.new(fruit)
fruit.headers["key"] = "fruit-value"
fruit.headers # => {"key"=>"fruit-value"}
apple.headers # => {}
Please note that if key was access token, for example, then subclasses couldn't get authorized, since apple.headers is empty.
I think you are seeing an empty header but if you try to access apple.headers["key"]
you will find the value. Did you try that?
Hi @rafaelfranca. Thanks for your fast response.
Yes, I find the value when manually accessing the key. However, the issue happens when ARes tries to fetch resources (e.g. Apple.all
.
See for example line 1108 in lib/active_resource/base.rb
:
format.decode(connection.get(path, headers).body)
Here it tries to connect using an empty headers
.
Right, that is a problem indeed. This gem has very low priority for me, so if you want, you could try to fix this case so the values in headers are kept the same.
Sure thing. Thanks for confirming that that is a problem.
Just ran into this myself! See #383 - hopefully it's the right fix. I think subclassing Hash in the first place was probably not a good idea, but this solves it without reimplementing it.
This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help.
If it is an issue and you can still reproduce this error on the main
branch,
please reply with all of the information you have about it in order to keep the issue open.
If it is a pull request and you are still interested on having it merged please make sure it can be merged clearly.
Thank you for all your contributions.
Still an issue.
This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help.
If it is an issue and you can still reproduce this error on the main
branch,
please reply with all of the information you have about it in order to keep the issue open.
If it is a pull request and you are still interested on having it merged please make sure it can be merged clearly.
Thank you for all your contributions.
Still an issue.
This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help.
If it is an issue and you can still reproduce this error on the main
branch,
please reply with all of the information you have about it in order to keep the issue open.
If it is a pull request and you are still interested on having it merged please make sure it can be merged clearly.
Thank you for all your contributions.
This is still an issue for me, is there a way to tackle this?
@bellef I moved the modification of the headers into the sub classes and called self.class.headers =