Idea: make `response.body` raise an error when a response_block was used #180

Open
myronmarston opened this Issue Jan 18, 2013 · 1 comment

Projects

None yet

2 participants

@myronmarston

In debugging vcr/vcr#245, I discovered that it is due to a bug in WebMock's excon adapter (reported there as bblimke/webmock#246). WebMock doesn't properly handle the case of a response_block being used; it assumes that response.body will have the response body (which isn't such a crazy assumption, really...), but excon's logic does not build up the body string on the response object when a response_block is used, presumably to avoid bloating memory by building up a string the client doesn't need since it's already handling it in the block.

It's an easy mistake to make, and it'd be nice if Excon surfaced the invalid use of response.body when the response block has been used. What do you think of either raising an error from response.body or returning an object from response.body that raises a clear error if any method is called on it? Either way, it would give the user a clear "you're using a response_block, so response.body isn't set; you shouldn't attempt to use it" message.

@geemus
Collaborator
geemus commented Jan 18, 2013

@myronmarston - I can certainly see how this would be helpful and avoid confusion. I think that the current behavior of NOT filling in the body is still likely to be the right thing to do (it assumes you already used the body and so don't need it, avoids memory bloat, etc), but it can lead to confusing interactions which your proposal would certainly fix. My preference, I think, would be to have response.body itself return an error in this case. I'll try to find some time to experiment with this in the not-too-distant future. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment