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 using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
The issue is about RESTish failing on HTTP status 204 (No Content). When a server returns a 204 response with no body, restish tries to parse the response body and fails with an "EOF" error.
Let me explore the repository structure first and understand the codebase, then find the relevant code in
request.goaround line 568 where the panic occurs.Let me start by exploring the repo structure and understanding the code.
Assistant
Let's look at the structure more carefully, especially the
clidirectory which containsrequest.go:Assistant
Let me check the go.mod to understand the module structure:
Assistant
The module has been renamed from
github.com/danielgtaylor/restishtogithub.com/rest-sh/restish/v2. Let me find the relevantrequest.gofileAssistant
The files are in
internal/cli/. Let me explore thatAssistant
Let me search for the
MakeRequestAndFormatfunctionAssistant
The function name may have changed. Let me look at the relevant files
Assistant
Let me explore the request and output packages
Assistant
Let me look at
do.goin the request package - this is likely where the actual HTTP request is made and response parsed.Assistant
Let me search for the "Parse response error" message
Assistant
Let me look at
request_exec.goAssistant
Let me look at
internal/output/response.goAssistant
Now I see the issue. The response has
Content-Encoding: gzipheader but with a 204 (No Content) status, there's no body to decompress. Let me look at theDecompressfunction in the content registryAssistant
Let me look at the content registry to see how Decompress works.
Assistant
Now I understand the issue! When the server returns HTTP 204 with
Content-Encoding: gzip, thedecodeBodyfunction tries to create a gzip decompressor on an empty body, andgzip.NewReaderfails with EOF because there's nothing to read.Let me confirm by looking at the gzip decompression
Assistant
Now let me create a reproduction script first
Assistant
Rename the file.
Assistant
Let me set up the environment.
Assistant
Confirmed the issue. Now let me fix the
decodeBodyfunction ininternal/output/response.goto handle responses that MUST NOT have a body (like 204 No Content).Assistant
Let me use the correct syntax for the open command.
Assistant
Now let me fix the
decodeBodyfunction. I'll add a check at the beginning for status codes that MUST NOT have a body (204, 304) and for Content-Length: 0.Assistant
Let me check that the
httppackage is already importedAssistant
Good,
net/httpis already imported. Now let me run the tests for the output packageAssistant
Let me look at the test file
Assistant
I see the issue. The tests fail because
ContentLengthdefaults to0(zero value ofint64) when not explicitly set. I should only check for status codes 204 and 304, not ContentLength. Let me fix this:Assistant
The edit introduced duplicate lines. Let me see the full function
Assistant
I need to remove the duplicate lines. Let me fix it
Assistant
Let me run the tests to see if they
Assistant
Tests pass. Let me clean up the extra
Assistant
Let me view the current content around that area
Assistant
There's a blank line at line 93 between the closing
}anddefer reader.Close(). Let me remove it. Let me useeditto fix it.Assistant
Now let me run the tests again to make sure everything passes
Assistant
Good. Let me now run the broader test suite to check for reg
Assistant
All tests pass. Let me write a quick simulation to verify the fix works for the exact
Assistant
Right, internal packages can't be imported externally. Let me write a test inside
Assistant
The 204 and 304 tests pass! The 200 gzip test failed because I used incorrect gzip data. Let me verify just the 204
Assistant
Both verification tests pass. Let me run the full
Assistant
All tests pass. Let me verify the final state of the fix
Assistant
Let me also check if there are other places that might need similar handling
Assistant
Let me check
internal/cli/http.goaround lines 667 and 689Assistant
Let me check who calls these
Assistant
Let me look at the context around lines 280-340 in http
Assistant
I should also fix
rawResponseBodyBytesanddecompressedResponseBodyinhttp.gofor the same issue, for consistency. Let me do that.Assistant
Let me fix
rawResponseBodyBytes:Assistant
Now fix
decompressedResponseBody:Now fixdecompressedResponseBodyAssistant
Good. Let me also check the stream.go that calls `decompressedResponseBody
Assistant
Now let me run the full test suite
Assistant
All tests pass. Let me also run the root package tests
Assistant
All tests pass across the entire project. Let me verify the changes with git
Assistant
The changes look clean and correct. Let me now go through the checklist:
-
Reproduced the error ✅ - Verified with a Go script that
gzip.NewReaderon an empty reader returnsEOF, matching the issue. -
Confirmed the fix resolves the error ✅ - Wrote verification tests for 204 and 304 with Content-Encoding: gzip, both pass successfully.
-
Thought about edge cases ✅:
- HTTP 204 No Content: handled (returns nil body immediately)
- HTTP 304 Not Modified: handled (returns nil body immediately)
- Normal 200+ responses with body and Content-Encoding: unaffected (tested via existing tests)
- Empty body on non-204/304 responses: handled by existing
len(raw) == 0check - Raw output mode: also fixed via
rawResponseBodyBytes - Streaming mode: also fixed via
decompressedResponseBody
-
Run existing tests ✅ - All tests pass across the entire project.
Now let me submit:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.