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

Access the HTTP::Request from the HTTP::Response #546

Merged
merged 2 commits into from Oct 21, 2019

Conversation

joshuaflanagan
Copy link
Contributor

This fixes #463

This will greatly enhance the abilities of pluggable Features by
being able to reference the Request that initiated a Response. It will make it easy to solves issues like #545.

I wasn't very happy with all the changes to the specs to put a "fake" Request, but felt it was pretty important that the Request object be mandatory when creating a Response. If we left it optional, it might be too easy to create a new code path (like the auto_inflate code) that doesn't properly set the initiating Request. Open to suggestions.

@joshuaflanagan joshuaflanagan force-pushed the response_request branch 2 times, most recently from 99ac40f to 3aae264 Compare April 24, 2019 23:01
joshuaflanagan added a commit to ShippingEasy/http that referenced this pull request Apr 24, 2019
This mirrors httprb#546, which has not been
merged yet.
joshuaflanagan added a commit to ShippingEasy/webmock that referenced this pull request Apr 25, 2019
Versions of HTTP.rb that allow access to the Request from the Response (httprb/http#546) require this change to continue working.
@natesholland natesholland mentioned this pull request May 7, 2019
@scarfacedeb scarfacedeb mentioned this pull request Sep 3, 2019
joshuaflanagan added a commit to ShippingEasy/webmock that referenced this pull request Oct 5, 2019
Versions of HTTP.rb that allow access to the Request from the Response (httprb/http#546) require this change to continue working.
@joshuaflanagan
Copy link
Contributor Author

What are the outstanding issues blocking this from being merged? I’ve been running this in production for 6 months now - happy to help get it merged so others can get the improved logging ability.

@tarcieri
Copy link
Member

@joshuaflanagan if you can rebase I will review/merge

@joshuaflanagan
Copy link
Contributor Author

@tarcieri ok done. The mobile github view made it harder to tell that there were merge conflicts. All fixed now.

@@ -199,6 +199,10 @@ def inspect
"#<#{self.class}/#{@version} #{verb.to_s.upcase} #{uri}>"
end

def self.example
new(:verb => :get, :uri => "http://example.com")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind moving this into the specs themselves so it isn't otherwise defined when the specs aren't running? You can still define it on HTTP::Request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with removing the example from the Request definition, but don't think it is worth re-opening the class in the specs. I think that would be more confusing to readers to see the class method invoked, but not defined where you would expect to find it.

I think the specs will be more readable to just repeat new(:verb => :get, :uri => "http://example.com") where needed. I can make that change if you agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds good

This fixes httprb#463

This will greatly enhance the abilities of pluggable `Features` by
being able to reference the Request that initiated a Response.
During normal operation, the Response#uri will be pulled from
the Request passed into the Response. However, we still allow explicitly
setting a `:uri` option when creating a Response, for backwards compatibility.

This was motivated by rubocop/code climate complaining that `Client#perform`
was now 1-line too long. I'll defer to the project maintainers to decide
if that is a good thing.
@tarcieri tarcieri merged commit 4430932 into httprb:master Oct 21, 2019
@tarcieri
Copy link
Member

Thank you! Sorry about the long delay

ixti added a commit that referenced this pull request Oct 21, 2019
Make them closer to reality.
Related to: #546
ixti added a commit that referenced this pull request Oct 21, 2019
ixti added a commit that referenced this pull request Oct 21, 2019
* Use Request#uri in Response

Response initialize requires Request object now, making uri parsing
absolutely redundant. And as it's a breaking change anyway - we should
get rid of `:uri` option completely.

NOTE: We need to update WebMock's adapter to reflect this change prior
releasing v5.0.0

* Update Changelog with #546 changes

SEE ALSO
--------

ShippingEasy/webmock@505ad00
@jrochkind
Copy link
Contributor

jrochkind commented Nov 20, 2019

Hi, this is listed as a breaking change at https://github.com/httprb/http/blob/master/CHANGES.md (presumably for 5.0.0.pre and an upcoming 5.0.0?)

From the PR description and diff, it's not yet clear to me what the nature of the breaking change is. Can you provide more guidance?

Is the backwards incompat only if you are manually instantiating an HTTP::Response, now it takes different args? (I'd imagine manually instantiating an HTTP::Response is relatively uncommon)

Thanks!

@tarcieri
Copy link
Member

@jrochkind previously the request URI was a directly accessible member of the response object. That was removed.

However, now the original request is a directly accessible member object of the response, and the request object knows the original URI. So, it removes direct access to the request URI, but it's still available via another layer of indirection through the request.

@ixti
Copy link
Member

ixti commented Nov 21, 2019

We have #uri on response delegated to #request in fact. The breaking change is that Response object was initialized with uri option before and now it requires response instead.

This is a breaking change for integrators like WebMock for example.

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

Successfully merging this pull request may close these issues.

Get the request object from the response?
4 participants