-
Notifications
You must be signed in to change notification settings - Fork 322
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
Get the request object from the response? #463
Comments
It's not doable atm - response has no "knowledege" of request (except request URI) - but in face of thinking about next major version update I really think we should change that. I also find it pretty useful to be able to get request object that was used to get response. |
You can "monkey-patch" client for your needs atm though: module HTTP
class Request
attr_accessor :req
end
class Client
def perform(req, options)
super(req, options).tap { |res| res.req = req }
end
end
end |
Thanks for the quick response, not sure how to use this piece of code though, I tried to
|
Oh. Sorry. I was thinking about different approach and forgot to "adapt" it to a more generic solution. Was thinking about re-defining module HTTP
class Response
attr_accessor :req
end
class Client
alias_method :__perform__, :perform
def perform(req, options)
__perform__(req, options).tap { |res| res.req = req }
end
end
end |
Thanks that worked! I agree this feature would be very interesting to have, it will aid in debugging a lot. Any ideas on where to start, to implement it in the gem? |
It's in fact trivial to implement in the gem, so instead of passing only https://github.com/httprb/http/blob/master/lib/http/client.rb#L74-L83 Obviosuly, Response needs to be updated to match this change as well. This will be a massive backward incompatible change - but that's fine for next (4.x) releases. /cc @httprb/core |
Awesome! that would be great to see it happen in v4.x. Thanks @ixti :) |
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
Any movement on this? Part of my requirement in choosing an HTTP lib is that I can easily dump out both the assembled request and the response to database audit columns. As it stands, I have to build up a request manually from an outer wrapper that takes the args I will pass to httprb. |
I really enjoy working with this library, except for the lacking debug of the request object. Any movement on this (outside of a monkey patch) would be great. |
If @joshuaflanagan can update #546 I'd consider merging it |
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
This fixes httprb#463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
This fixes #463 This will greatly enhance the abilities of pluggable `Features` by being able to reference the Request that initiated a Response.
Is it possible to get the request object from the response?
Sometimes if not always when debugging if a response failed I need to know if I missed something on the request body or headers, but now I have no way to do that. if there is any work around that would be great.
Thanks.
HTTPrb v3.0.0
ruby v2.3.5
The text was updated successfully, but these errors were encountered: