ISSUE DESCRIPTION Fail on HTTP Status 204 (No Content) Hello, I'm using Synadia Cloud…
- User
ISSUE DESCRIPTION
Fail on HTTP Status 204 (No Content) Hello,
I'm using Synadia Cloud which has a
DELETEAPI that returns a response with no body.code$ restish synadia delete-nats-user --help Deletes a NATS user from an account ## Argument Schema: { user-id: (string) } ## Responses 204/400/401/403/404 Response has no bodyIn this case, it's expected to have an empty body. Nevertheless,
restishfails with the error:codeERROR: Parse response error ERROR: Caught error: EOFHere is the full log:
code Assistant
Let me analyze the issue. The problem is that when an HTTP API returns a 204 No Content status (which has no body),
restishfails with "Parse response error" and "EOF" error. This happens because the code is trying to parse/decode an empty body.Let me start by exploring the repository structure to understand the codebase.
Assistant
Based on the error log, the issue is in
cli/request.goaround line 568. Let me look at that file and the relevant code paths.Assistant
The stack trace mentions
/home/runner/work/restish/restish/cli/request.gobut that path doesn't exist. The repository structure is different. Let me search for where the response parsing and decoding happens.Assistant
Let me search for where responses are being decoded, particularly with gzip handling.
Assistant
Let me search for where the response body parsing happens and where the EOF error might occur:
Assistant
Let me look at the content registry and defaults where gzip handling happens:
Assistant
Now let me look at the content registry where the encoding/content-type handling happens:
Assistant
Now let me look at where responses are read and decoded - specifically in the stream.go file:
Assistant
Now let me look at where the response body is read - there should be a function that handles the decompressed body and then decodes it:
Assistant
Let me look at the
normalizeHTTPResponsefunction where the body is read:Assistant
Now I can see the issue is in
output.Normalize. Let me look at that function:Assistant
I found the issue! In
decodeBody, the problem is that when a response hasContent-Encoding: gzipbut the body is empty (like 204 No Content), the code still tries to decompress the body usingreg.Decompress(encoding, resp.Body). The gzip decompressor then gets an EOF when trying to read the gzip header from an empty body.Let me look at where the decompress function is called and check how the gzip decompressor handles empty input:
Assistant
The issue is clear now. When a 204 response has
Content-Encoding: gzipbut an empty body, thedefaultGzipDecompressfunction creates a gzip reader which then fails with EOF when trying to read the gzip header. The fix should be indecodeBodyin/restish/internal/output/response.go- when the body is empty (like 204 No Content), we should skip decompression.Let me first create a test script to reproduce the issue:
Assistant
Let me check if there are existing tests for response.go:
Assistant
I can see there's already a test
TestNormalize_EmptyBodyfor empty bodies without Content-Encoding. But the issue is when the response hasContent-Encoding: gzipwith an empty body (204 No Content). Let me write a reproduction script:Assistant
Let me run this test as part of the test file in the output package:
Assistant
I've confirmed the issue. The error is "decompressing response: EOF" which matches the issue description. Now let me fix the
decodeBodyfunction to handle empty bodies before attempting decompression:Assistant
Now let me look at the
decodeBodyfunction again and implement the fix. The solution should check if the body is empty (e.g., for 204 responses) before trying to decompress:Assistant
Now I can see the issue clearly. The problem is in
decodeBody:- Line 82-83: It gets the Content-Encoding header and tries to decompress
- Line 83:
reg.Decompress(encoding, resp.Body)creates a gzip reader even when the body is empty - Line 90:
io.ReadAlltries to read from the gzip reader, which fails with EOF because there's no gzip header in an empty body
The fix should be to check if the body is empty before attempting to decompress. For responses with no body (like 204), we should skip decompression entirely.
Let me implement the fix:
Assistant
Wait, I need to think about this more carefully. The issue is that
http.NoBodyis a specific sentinel value, but in real HTTP responses, the body might be anio.ReadCloserthat returns EOF immediately (not specificallyhttp.NoBody). Let me think about edge cases:- 204 No Content with
http.NoBody: This is what my fix handles - 204 No Content with an empty body reader (like
io.NopCloser(strings.NewReader(""))): This case would still fail because the body isn'thttp.NoBodybut returns EOF when read
Let me check how real HTTP responses are handled. Looking at the log from the issue, the response comes from
request.Dowhich would give us a real response body. The issue is that the body is empty but has aContent-Encoding: gzipheader.- 204 No Content with
Assistant
As I suspected, the
http.NoBodycheck handles one case but not the case where the body is an empty reader (likeio.NopCloser(strings.NewReader(""))). This is the real-world scenario because the HTTP transport creates a body reader that returns EOF immediately for empty responses.I need a more robust fix. The best approach is to try reading the body first without decompression, and if the body is empty, skip decompression. Or, we could handle the EOF error from decompression when the body is known to be empty.
Let me think about this more carefully. The real issue is:
- The server sends
Content-Encoding: gzipheader - But the body is empty (0 bytes)
- The gzip reader expects a gzip header but gets nothing
The correct fix is to read the raw body first, check if it's empty, and only then try to decompress if it's non-empty. But that changes the flow significantly.
Actually, looking at this again - the simplest and most robust fix is to read from the body (without decompression) first, then if there's content, decompress it. But this doesn't work well with streaming.
A better approach: Handle the case where decompression fails with EOF but the body was actually empty. Let me modify the approach:
- The server sends
Assistant
I need a different approach. The issue is that the decompressor (gzip reader) fails when the body is empty. The fix should read the body first, then only decompress if there's content. Let me rewrite the
decodeBodyfunction:Assistant
Now let me run the tests to see if this fix works:
Assistant
The error happens during
reg.Decompressitself, not during the read. Let me look at what errorgzip.NewReaderreturns when the input is empty:Assistant
So the error occurs when creating the gzip reader, not when reading from it. The
gzip.NewReaderfunction returnsEOFwhen the input is empty. This means my fix in the read path won't help - I need to handle this error at the decompress stage.The fix should be: when creating a decompressor fails with EOF and we have a content encoding, we should check if this is an empty body situation and treat it as such.
Assistant
Now let me test this fix:
Assistant
Both tests pass. Now let me remove the test file I created and run all existing tests in the output package to make sure I haven't broken anything:
Assistant
Assistant
I need to properly invoke the bash_terminal function.
Assistant
All tests pass. Let me also run tests in other packages that might be affected by this change:
Assistant
Let me continue running the tests to make sure everything passes.
Assistant
All CLI tests pass. Let me also run the content package tests since that's related to the decompression logic:
Assistant
Let me also verify edge cases - what happens with corrupted gzip data:
Assistant
I see that brotli and deflate fail at read time, not at decompressor creation time. I need to also handle EOF errors during reading when no data has been read. Let me update the fix:
Assistant
I need to run the tests again to verify that the fix handles all the edge cases properly.
Assistant
Now let me run all the edge case tests including corrupted data and valid gzip:
Assistant
Excellent! All tests pass:
- Empty body with gzip encoding - PASS
- Empty body with brotli encoding - PASS
- Empty body with deflate encoding - PASS
- Corrupted gzip body still errors (correct behavior) - PASS
- Valid gzip body works - PASS
Now let me clean up my test file and run all the output package tests to make sure nothing is broken:
Assistant
Now let me run a broader set of tests to make sure nothing is broken. Let me run all tests in the repository.
Assistant
All tests pass. Let me view the final state of my changes:
Assistant
The diff shows my changes to
internal/output/response.go. Let me verify the final code looks correct:Assistant
The fix is complete. Let me go through the checklist:
Checklist Review
-
[x] If an error was reported in the issue description, I have successfully reproduced it.
- I confirmed the error by creating a test with a 204 response with
Content-Encoding: gzipand an empty body, which produced the "decompressing response: EOF" error.
- I confirmed the error by creating a test with a 204 response with
-
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I verified that the fix resolves the error for gzip, brotli, and deflate encodings with empty bodies.
-
[x] I have thought about edge cases and made sure my fix handles them as well.
- http.NoBody: Handled by checking
resp.Body == http.NoBody - gzip with empty body: gzip fails at decompressor creation with EOF - handled
- brotli/deflate with empty body: These fail at read time with EOF/ErrUnexpectedEOF - handled
- Corrupted gzip data: Still produces proper error (not swallowed)
- http.NoBody: Handled by checking
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.