-
Notifications
You must be signed in to change notification settings - Fork 124
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
fix: don't update Data when body is empty #125
Conversation
Codecov Report
@@ Coverage Diff @@
## main #125 +/- ##
==========================================
- Coverage 98.41% 98.20% -0.21%
==========================================
Files 8 8
Lines 1448 1450 +2
==========================================
- Hits 1425 1424 -1
- Misses 17 19 +2
- Partials 6 7 +1
|
+1, I agree that this change makes sense.
That's a good question, let me think about it a little bit this morning. My first instinct is that an empty string is a reasonable enough compromise that, even if I might take a quick pass locally just to see how feasible something like a
Also a good question, and I'm sorry for any confusion! I know the test suite is a bit of a mess, and I have no idea off the top of my head how best to test this, but lemme take a look. |
Okay, took a quick pass at this, and I don't think it's worth all of the additional overhead that would be required to marshal empty bodies as The custom type approach feels like a whole lot of complexity (including a particularly heavyweight custom |
Oh boy, I just spent wayyyy too long trying to figure out why the existing test cases for requests with empty bodies were showing a different behavior from the curl test (either the tests should have failed, or the curl should have returned an empty string for the Turns out it's down to a couple of things:
So, weirdly, we already have unit tests in place that describe the behavior we're actually implementing in this pull request, they just weren't testing the actual live behavior in the face of an actual HTTP request. My inclination is to land this change as-is and then I'll follow up with an update to the test suite to stop using the recorder approach. I've considered that a number of times in the past for vague notions of correctness, but this is the first time I can remember running into an actual behavior difference that mattered quite so much. |
FYI, this was released in v2.9.0 |
Thanks so much! I want to add that I've found this project really useful, thanks for all the work |
In the course of validating #125, we discovered that using the stdlib's [`httptest.ResponseRecorder`][0] mechanism to drive the vast majority of our unit tests led to some slight brokenness due to subtle differences in the way those "simulated" requests are handled vs "real" requests to a live HTTP server, as [explained in this comment][1]. That prompted me to do a big ass refactor of the entire test suite, swapping httptest.ResponseRecorder for interacting with a live server instance via [`httptest.Server`][2]. This should make the test suite more accurate and reliable in the long run by ensuring that the vast majority of tests are making actual HTTP requests and reading responses from the wire. Note that updating these tests also uncovered a few minor bugs in existing handler code, fixed in a separate commit for visibility. P.S. I'm awfully sorry to anyone who tries to merge or rebase local test changes after this refactor lands, that is goign to be a nightmare. If you run into issues resolving conflicts, feel free to ping me and I can try to help! [0]: https://pkg.go.dev/net/http/httptest#ResponseRecorder [1]: #125 (comment) [2]: https://pkg.go.dev/net/http/httptest#Server
When a request to
/anything
has an empty body, thedata
field of the output should be the empty string. Currently,go-httpbin is returning
data:application/octet-stream;base64,`.files
,form
, andjson
, but also would require deeper changes sinceData
is stored as a string not a pointer, and I didn't want to mess with things any more than I had to. An empty string works fine for my purposesThis PR closes #124. Before:
After: