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

Make it easier to access submitted data #61

Open
betesh opened this issue Aug 2, 2017 · 1 comment
Open

Make it easier to access submitted data #61

betesh opened this issue Aug 2, 2017 · 1 comment

Comments

@betesh
Copy link

betesh commented Aug 2, 2017

Right now, if I want to verify that I'm POST'ing the right data, I need to do something like this:

FakeWeb.register_uri(:post, my_url, body: 'i-dont-care-about-the-response-only-the-request')
do_something_that_hits_my_url
request_data = CGI.parse FakeWeb.last_request.body_stream.instance_variable_get('@stream').string
expect(request_data).to ...

Line 3 of this example should be encapsulated. For instance, it could be exposed as FakeWeb.last_request.form_data

@matthutchinson
Copy link

I can confirm this is necessary when using FakeWeb to stub requests from the RestClient gem (2.0.0+).

Without inspecting this IO stream data, there's no way to see what was sent. Since FakeWeb.last_request.body will be nil in the common case of sending a String payload with RestClient::Request.execute(...).

It is due to this code in RestClient::Request creating a RestClient::Payload::Base (or similar depending on the type of body data) and attaching it to the Net::HTTP request body_stream (rather than body).

This was documented here as a performance improvement with the release of RestClient v2.0.0

Add actual support for streaming request payloads. Previously rest-client would call .to_s even on RestClient::Payload::Streamed objects. Instead, treat any object that responds to .read as a streaming payload and pass it through to .body_stream= on the Net:HTTP object. This massively reduces the memory required for large file uploads.

This isn't an issue with Net::HTTP unless you're setting body_stream directly on the request.

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

No branches or pull requests

2 participants