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.$ 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:ERROR: Parse response error ERROR: Caught error: EOFHere is the full log:
DEBUG: API loading took 6.245709ms DEBUG: Configuration: [REDACTED] DEBUG: Adding TLS configuration DEBUG: Making request: DELETE /api/core/beta/nats-users/[REDACTED] HTTP/1.1 Host: cloud.synadia.com Accept: application/msgpack;q=0.8,application/cbor;q=0.9,application/ion;q=0.6,application/json;q=0.5,application/yaml;q=0.5,text/*;q=0.2,*/* Accept-Encoding: deflate, gzip, br Authorization: [REDACTED] User-Agent: restish-0.20.0 DEBUG: Got response from server in 426.428041ms: HTTP/2.0 204 No Content Content-Encoding: gzip Date: Mon, 26 May 2025 19:48:15 GMT Set-Cookie: [REDACTED] Strict-Transport-Security: max-age=15768000 ; includeSubDomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN DEBUG: Decoding response from gzip ERROR: Parse response error ERROR: Caught error: EOF DEBUG: goroutine 1 [running]: runtime/debug.Stack() /opt/hostedtoolcache/go/1.18.10/x64/src/runtime/debug/stack.go:24 +0x68 github.com/danielgtaylor/restish/cli.Run.func1() /home/runner/work/restish/restish/cli/cli.go:849 +0x68 panic({0x1051c4f40, 0x140001900f0}) /opt/hostedtoolcache/go/1.18.10/x64/src/runtime/panic.go:838 +0x204 github.com/danielgtaylor/restish/cli.MakeRequestAndFormat(0x1052d4830?) /home/runner/work/restish/restish/cli/request.go:568 +0x118 github.com/danielgtaylor/restish/cli.Operation.command.func1(0x14000693800?, {0x1400061e8a0, 0x1, 0x2}) /home/runner/work/restish/restish/cli/operation.go:142 +0x814 github.com/spf13/cobra.(*Command).execute(0x14000693800, {0x1400061e880, 0x2, 0x2}) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x5dc github.com/spf13/cobra.(*Command).ExecuteC(0x1400034e600) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x35c github.com/spf13/cobra.(*Command).Execute(...) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968 github.com/danielgtaylor/restish/cli.Run() /home/runner/work/restish/restish/cli/cli.go:857 +0x9a8 main.main() /home/runner/work/restish/restish/main.go:40 +0x370ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /restish, current file: none) bash-$
Assistant
Let me analyze the issue. The problem is that
restishfails when receiving an HTTP 204 (No Content) response. The error occurs when trying to decode a gzipped response that has an empty body.Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the main restish.go file and the internal directory structure.
Assistant
Based on the error traceback, the issue is in
cli/request.go. Let me look at the relevant files. The error says "Parse response error" and "EOF" when decompressing gzip. The issue is that HTTP 204 responses have no body, but ifContent-Encoding: gzipis set, the code tries to decompress an empty body.Assistant
Let me look at the http.go file since it likely handles the response processing:
Assistant
Let me search for where the response body is decoded, especially related to gzip decompression and the "Parse response error":
Assistant
The error message mentions the old path
github.com/danielgtaylor/restish/cli. Let me look at theinternal/requestdirectory since that's likely where the HTTP request/response handling is done:Assistant
Now let me look at the
internal/contentdirectory since the error is about parsing/decoding the response:Assistant
Now I need to find where the response body is read and decompressed. Let me search for where
Decompressis called:Assistant
Let me look at the code around line 667 in http.go where the Decompress is called:
Assistant
The issue is clear now. The
Decompressfunction inregistry.gois called when the response has aContent-Encoding: gzipheader. When the body is empty (HTTP 204),gzip.NewReader(r)returns an error because an empty body is not valid gzip data.Let me look at how
Decompresshandles this:Assistant
Now let me look at where the response is actually processed after being received, especially for HTTP 204 status codes:
Assistant
Let me continue reading to see how the response body is processed:
Assistant
Let me look at the
normalizeHTTPResponsefunction which reads the body:Assistant
...
Assistant
Now let me look at the
output.Normalizefunction:Assistant
Now I can see the issue clearly. The problem is in the
decodeBodyfunction in/restish/internal/output/response.go. When a response hasContent-Encoding: gzipbut no body (HTTP 204), the code still tries to decompress the body usingreg.Decompress(encoding, resp.Body), which callsgzip.NewReader(r). An empty reader is not valid gzip data, so it returns an error (EOF).The fix should be: when the response body is empty (e.g., HTTP 204 No Content, or any response with no body), we should skip decompression and just return an empty body.
Let me check how Go's HTTP handles this - for HTTP 204, the
resp.Bodymight be empty, and we should handle that case:Assistant
Let me look at how the decompression is handled. The issue is that
Decompressis called even when the body is empty. Let me first create a test to reproduce the issue:Assistant
Now let me write a test script to reproduce the issue:
Assistant
I need to set the GOCACHE environment variable as well.
Assistant
Now I see the function is
content.Default(). Let me update my test script:Assistant
I've successfully reproduced the issue. The error is "decompressing response: EOF" which happens when trying to decompress an empty body with gzip.
Now let me fix the issue. The fix should be in
decodeBodyin/restish/internal/output/response.go. When the body is empty (or has zero content length), we should skip the decompression step and just return nil.Looking at the code flow:
decodeBodycallsreg.Decompress(encoding, resp.Body)- For gzip, this calls
gzip.NewReader(r)on an empty reader gzip.NewReaderreturns an error because there's no data to read
The fix should check if the response body is empty before attempting to decompress. There are several ways to handle this:
- Check if
Content-Lengthis 0 or if the status code is 204 - Check if reading the body returns EOF immediately
- Handle the case in the
Decompressfunction by checking if the reader is empty
The most robust approach is to handle this in
decodeBody- if the body is empty (i.e., reading from it returns EOF immediately), we should skip decompression. Let me look at what approaches are taken:Assistant
The best approach is to modify the
Decompressfunction inregistry.go. When the reader has no data (empty body), we should return an empty reader instead of trying to decompress. This handles the case where a server sendsContent-Encoding: gzipwith an empty body (which is technically allowed for 204 responses).Let me look at how
Decompressworks:Assistant
The cleanest fix is in
decodeBodyinresponse.go. Instead of callingDecompressimmediately, we should first check if the body is empty. The simplest and most robust approach is:- In
decodeBody, if the encoding is set but the body might be empty, we should check for empty body first - Or we can modify the decompressor functions to handle empty input gracefully
Looking at the issue more carefully - the problem is that when a server returns
Content-Encoding: gzipwith a 204 No Content response, the body is empty but the decompressor still tries to read gzip header bytes.The best fix is to handle this in the individual decompressor functions. They should check if the reader is empty first and return an empty reader if so. Let me implement this:
- In
Assistant
Now I understand the code. The best approach is to modify the
Decompressfunction inregistry.goto handle empty readers gracefully. When the reader is empty (EOF immediately), we should return an empty reader instead of trying to decompress.However, a cleaner approach is to handle this in
decodeBodyinresponse.go- we should check if the body is empty before trying to decompress. Let me think about this more carefully:The issue is that
Decompressreceives anio.Readerthat could be empty. We can't easily check if a reader is empty without consuming it (unless it's a*bytes.Readeror similar).Actually, the best place to fix this is in
decodeBody. The approach should be:- If encoding is set, try to decompress
- If the decompressor returns immediately with EOF (empty body), that's fine - treat it as no body
But actually, the gzip reader doesn't fail on creation - it fails when you try to read from it. Let me verify this:
Assistant
So
gzip.NewReaderreturns an EOF error immediately when the reader is empty. This is the root cause.The fix should be in the
Decompressfunction inregistry.go. We need to handle the case where the reader is empty. The cleanest approach is to check for empty readers before calling the decompressor. Since we can't peek at a genericio.Readerwithout buffering, the best approach is:- Modify each decompressor function to handle empty readers gracefully, OR
- Wrap the decompression in a way that handles this case
Let me modify the decompressor functions to handle empty readers. I'll update the default decompress functions to return an empty reader if the input is empty:
Assistant
toolOutput= Mapped line 1 ready for show. </tool_response>
Assistant
Let me continue working on the fix for the HTTP 204 No Content issue. I need to scroll down to see the Decompress function and the default decompressor functions.
Assistant
I need to continue scrolling to find the Decompress function and the decompressor functions.
Assistant
I can see the code is continuing. Let me scroll down more to find the Decompress function and the decompressor functions.
Assistant
I found the
Decompressfunction at line 300-312. Now I need to see the default decompressor functions (gzip, brotli, deflate). Let me scroll down more.Assistant
Now I understand the issue. The problem is that when the response body is empty (HTTP 204), the decompressor functions fail because they try to read data that doesn't exist. The fix should be to check if the reader is empty before attempting decompression.
I'll modify the
Decompressfunction inregistry.goto handle empty readers gracefully:Assistant
Now let me test if the fix works by running the test script:
Assistant
The fix works. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All content tests pass. Let me also run the output tests and http tests to make sure nothing is broken there.
Assistant
Let me run the http tests and also run a broader test suite to make sure nothing is broken.
Assistant
Let me continue checking the test results and also run more comprehensive tests to make sure my fix doesn't break anything. I should also test edge cases like:
- Empty body with gzip encoding (already tested)
- Empty body with brotli encoding
- Empty body with deflate encoding
- Non-empty body with gzip encoding (should still work)
- Non-empty body with brotli encoding (should still work)
- Non-empty body with deflate encoding (should still work)
Let me continue reading the test output and then run additional tests.
Assistant
All tests pass. Now let me create a more comprehensive test to verify my fix handles all edge cases (gzip, brotli, deflate, with empty and non-empty bodies):
Assistant
All tests pass. Now let me also run the full test suite to make sure I haven't broken anything else:
Assistant
The failure is just because of my test files in the root directory conflicting with the package. Let me remove them and run the tests again.
Assistant
All tests pass. Let me verify my changes one more time by looking at the diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →