-
Notifications
You must be signed in to change notification settings - Fork 706
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
Body and Rawbody #600
Comments
@Joseph94m Thanks for reaching out. I understand the details you have given about Feel free to share improvement suggestion. |
@Joseph94m I have added |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been banging my head against the wall for a day, so I thought why not swing by and say hi 👯
There are two main subjects I will tackle in this post - not necessarily issues or bugs. Maybe just in need of enlightenment.
1- In resty v2, Body() and RawBody() are defined as follows:
It seems weird to me that we check for RawResponse == nil in Body(), why not just return r.body? Maybe,I'm just being really pedantic here but hey!
2- I came across 1- as I was trying to mock GET requests performed through resty for testing purposes...
Normally I use httpmock, but for my current project I wanted to to have 2 levels of testing, 1/ with httpmock and 2/ more of a low level testing using my own implementation with custom responses.
Through a custom request handler, I have:
When called, for example:
Exeucting the GET function returns a response. If i call response.Body(), I will receive an empty array as response.Body() returns r.body and I cannot set this variable because it is unexported.
Is there a way I can set a custom body field directly in the Response structure instead of the RawResponse? I've banged my head against this trying to find workarounds with the Writer and Reader interfaces in resty but no luck.
Or am I doing some anti-pattern here? Maybe I should just use response.RawBody() instead of response.Body() but that seems awfully barbaric as we call response.Body() in our main functions, and I would hate to swap it with response.RawBody() just so that I can test it....
Thanks !
The text was updated successfully, but these errors were encountered: