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 +0x370Interface
No new interfaces are introduced.
ADDITIONAL 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 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
Let me start by exploring the repository structure to understand the codebase and then find where the response parsing happens that's causing the "EOF" error when handling HTTP 204 responses.
Assistant
Let me look at the error in the stack trace. The error occurs in
cli/request.go:568in theMakeRequestAndFormatfunction. Let me explore the CLI directory structure and find the request.go file.<tool_call> <function=bash_terminal> <parameter=command> find . -name "request.go" -type f </tool_call>
Assistant
Let me search for the request.go file properly.
Assistant
That's not the right request.go. The stack trace mentions
cli/request.go. Let me search in the cli directory.Assistant
The cli directory is in internal. Let me explore the internal/cli directory.
Assistant
I see the file is
request_exec.go. Let me look at line 568 where the error occurs according to the stack trace.Assistant
The file is only 418 lines, but the stack trace mentions line 568. Let me check if there's a request.go file or look at the cli.go file which also has a reference in the stack trace.
<tool_call> <function=bash_terminal> <parameter=command> wc -l internal/cli/cli.go </tool_call>
Assistant
Let me continue investigating the issue. I need to look at the request execution code to understand how responses are parsed.
Assistant
The file names might have changed since the version in the stack trace. Let me search for the function
MakeRequestAndFormatto understand where the error is happening.Assistant
The error is "EOF" when parsing a response with no body (HTTP 204 No Content). Let me search for response parsing code in the request handling files.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "Parse response" internal/cli/ </tool_call>
Assistant
Let me search for "Parse response" in the codebase to find where the error is generated.
Assistant
Let me try a simpler search:
Assistant
Let me search more broadly in the codebase. The error message "Parse response error" might be in a different format.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "response error" . 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for response parsing code in the codebase. I should look at the http.go file and request_exec.go file since those are likely where response parsing happens.
Assistant
Let me look at the responseBodyReadError function and the responseBodyAbsent function to understand how responses with empty bodies are handled.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1452,1470p' internal/cli/http.go </tool_call>
Assistant
Let me look at the responseBodyReadError function and surrounding code to understand how response body parsing works.
Assistant
Let me look at the code around line 670-700 to see how response bodies are read.
Assistant
Let me look at the request_exec.go file to understand how responses are processed.
Assistant
Now let me look at the output.Normalize function to see how responses are normalized and where the error might be happening:
<tool_call> <function=bash_terminal> <parameter=command> find . -name ".go" -path "/output/*" | head -10 </tool_call>
Assistant
Let me search for the output package to find the Normalize function.
Assistant
Let me look at the response.go file in the output package to find the Normalize function.
Assistant
Now I can see the issue. In the
decodeBodyfunction, when the response body is empty (like for HTTP 204 No Content), the function correctly returnsnil, nil, nil. However, the issue might be happening earlier in the decompression step.Let me look at the
reg.Decompressfunction to see how it handles empty bodies:<tool_call> <function=bash_terminal> <parameter=command> find . -path "/content/.go" -type f </tool_call>
Assistant
Let me search for the content package to understand how decompression works.
Assistant
Let me look at the registry.go file to find the Decompress function.
Assistant
Now I can see the issue! Looking at the
defaultGzipDecompressfunction:func defaultGzipDecompress(r io.Reader) (io.ReadCloser, error) { return gzip.NewReader(r) }When the response body is empty (like HTTP 204 No Content), and the Content-Encoding header is set to gzip, the
gzip.NewReader(r)function is called with an empty reader. This can cause an "EOF" error becausegzip.NewReadertries to read the gzip header immediately and fails when there's no data.The issue is that for HTTP 204 No Content responses, even if the server says
Content-Encoding: gzip, there is no actual body to decompress. The fix should be to handle the case where the response body is empty before attempting to decompress it.Let me look at how this is called in the code to understand the flow better:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "decodeBody|Normalize" internal/output/response.go </tool_call>
Assistant
Let me search for where decodeBody is called to understand the flow better.
Assistant
The issue is that when
gzip.NewReader(r)is called with an empty reader, it tries to read the gzip header and fails with EOF. This happens before we check if the body is empty indecodeBody.The fix should be to check if the body is empty before trying to decompress, or to handle the error from
gzip.NewReadergracefully.Let me first create a reproduction script to verify the issue:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && cat > /tmp/test_204.go << 'EOF' package main
import ( "bytes" "fmt" "compress/gzip" "io" )
func main() { // Simulate empty body with gzip encoding emptyBody := bytes.NewReader([]byte{})
// This is what the current code does - it fails with EOF reader, err := gzip.NewReader(emptyBody) if err != nil { fmt.Printf("Error creating gzip reader: %v\n", err) } else { // Try to read from it data, err := io.ReadAll(reader) fmt.Printf("Read %d bytes, error: %v\n", len(data), err) reader.Close() }} EOF go run /tmp/test_204.go </tool_call>
Assistant
Let me run the test script to reproduce the issue.
Assistant
Let me set the required environment variables and try again.
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && export HOME=/tmp && export XDG_CACHE_HOME=/tmp/cache && go run /tmp/test_204.go </tool_call>
Assistant
Let me try again with the environment variables set.
Assistant
I've confirmed the issue. When
gzip.NewReaderis called with an empty reader (for HTTP 204 No Content responses), it returns an EOF error. Now let me fix thedecodeBodyfunction ininternal/output/response.goto handle empty response bodies before attempting decompression.Assistant
Now I understand the issue. The
decodeBodyfunction tries to decompress the response body first, but when the body is empty (like HTTP 204 No Content), the gzip decompressor fails with EOF.The fix should be to check if the response body is empty (or 204 status) before attempting to decompress, OR handle the EOF error from decompression gracefully.
Looking at the code, I see there's already logic to return
nil, nil, nilwhenlen(raw) == 0, but the problem is that the decompression fails before we can read the body.There are two possible approaches:
- Check if the response body is empty before decompression
- Handle the EOF error from decompression when the body is empty
I think the cleanest approach is to check the status code - HTTP 204 responses should never have a body, so we should skip decompression for them. Also, we could check if the body is empty before trying to decompress.
Assistant
Let me first read the file properly and understand its structure better before making the fix. I need to see the full content to understand what needs to be changed.
Assistant
Now I need to fix the
decodeBodyfunction to handle empty response bodies gracefully. The issue is that when the response body is empty (like HTTP 204 No Content), thereg.Decompresscall fails with EOF when trying to create a gzip reader.The fix should check if the body is empty before attempting decompression. We can do this by:
- Checking if Content-Length is 0, or
- Trying to read a small amount of data first
Let me also look at what HTTP status codes should have no body according to RFC 7230-7235:
- 1xx (Informational): no body
- 204 (No Content): no body
- 304 (Not Modified): no body
The simplest and most robust fix is to check if Content-Length is 0 or if the status code is one that should have no body before attempting decompression. However, a more robust approach is to handle the EOF error from decompression gracefully - if decompression fails with EOF and the error is "unexpected EOF" or similar, we can treat the body as empty.
Assistant
Let me examine the decodeBody function to create a proper fix:
Assistant
Assistant
Now let me apply the fix to the response.go file:
Assistant
Let me verify the changes were applied correctly:
Assistant
Let me see the rest of the file to make sure the shouldSkipBody function is complete:
Assistant
I see there's some leftover code from the sed replacement. Let me view the entire file and fix it properly:
Assistant
I see there's a duplicate code segment at lines 146-148 that needs to be removed. Let me fix this:
<tool_call> <function=bash_terminal> <parameter=command> sed -i '146,148d' internal/output/response.go </tool_call>
Assistant
Let me verify the fix is complete by viewing the file again.
Assistant
I see there's still a duplicate line. Let me fix this properly:
Assistant
I need to remove the duplicate lines that are after the
shouldSkipBodyfunction:<tool_call> <function=bash_terminal> <parameter=command> sed -i '148,150d' internal/output/response.go </tool_call>
Assistant
Let me verify the fix is complete by viewing the relevant section of the file.
Assistant
I see the duplicate lines are still there. Let me use the
editcommand to fix this properly.Assistant
Let me use the special commands to edit the file properly.
Assistant
Now let me verify the fix is complete:
Assistant
Let me view the entire file to understand the structure and fix it properly:
Assistant
The file has a syntax error - the
shouldSkipBodyfunction is missing its closing brace. Let me fix this by using the edit command:Assistant
Let me verify the fix is complete by viewing the file:
Assistant
Let me use the special
editcommand to fix the missing closing brace:Assistant
Let me verify the fix:
Assistant
Now let me verify the fix is correct by checking if the file compiles:
Assistant
It's downloading dependencies. Let me wait for the build to complete.
Assistant
The package builds successfully. Now let me run the existing tests to make sure the fix doesn't break anything:
Assistant
All tests pass. Now let me run the full test suite to make sure the fix doesn't break anything else:
Assistant
All tests pass. Now let me create a test script to verify that the fix works for the specific issue described in the bug report (HTTP 204 No Content response with gzip encoding):
Assistant
Assistant
Let me create the test file and run the tests to verify the fix.
Assistant
Now let me run the new tests to verify the fix:
Assistant
The test for compressed body with non-empty content is failing because I didn't set the correct Content-Length. Let me fix that test case and also add a test for the exact issue described in the bug report (HTTP 204 with gzip encoding that sends no data at all):
Assistant
Let me run the tests again to see if they pass now.
Assistant
I need to import "net/url" package for the http.URL type. Let me fix that:
Assistant
Let me run the tests again:
Assistant
The test for non-empty compressed body is failing because the test sets Content-Length: 0 but still sends data. Let me fix the test:
Assistant
Let me run the tests again to see if they pass now:
Assistant
All the new tests pass! Now let me run all the tests in the output package to make sure the fix doesn't break any existing functionality:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && export HOME=/tmp && export XDG_CACHE_HOME=/tmp/cache && go test -v ./internal/output/... 2>&1 | tail -50 </tool_call>
Assistant
Let me run the full test suite for the output package and then the entire project to make sure everything still works.
Assistant
Good, all tests pass! Now let me run the full test suite to ensure the fix doesn't break anything else:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && export HOME=/tmp && export XDG_CACHE_HOME=/tmp/cache && go test ./... 2>&1 </tool_call>
Assistant
Let me run the full test suite:
Assistant
All tests pass. Now let me verify the changes I made by looking at the git diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && git diff internal/output/response.go </tool_call>
Assistant
Let me run the git diff command to see the changes I made to the response.go file.
Assistant
There's a small formatting issue - the closing brace
}from theshouldSkipBodyfunction is missing beforefunc responseDecodeError. Let me fix that:<tool_call> <function=bash_terminal> <parameter=command> cd /restish && sed -n '145,155p' internal/output/response.go </tool_call>
Assistant
Let me view the relevant section of the file to see the formatting issue:
Assistant
Let me fix the formatting issue by adding a blank line between the
shouldSkipBodyfunction andresponseDecodeError:Assistant
Let me verify the fix and run the tests again:
Assistant
Let me fix the formatting issue with a simpler sed command:
Assistant
Let me verify the fix and run the tests again:
Assistant
Good, the formatting is fixed now. Let me run the tests to make sure everything still works:
Assistant
Let me run the full test suite and then check the git diff:
Assistant
All tests pass. Now let me check the final git diff to see the changes I made:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && git diff internal/output/response.go </tool_call>
Assistant
Let me run the git diff command to see the changes I made.
Assistant
The fix looks good. Let me also check if the test file was created properly:
<tool_call> <function=bash_terminal> <parameter=command> cd /restish && git status </tool_call>
Assistant
Let me check the git status to see the changes I've made.
Assistant
The fix is complete. Let me summarize what I did:
-
Identified the issue: When a server returns HTTP 204 No Content with
Content-Encoding: gzip, thegzip.NewReaderfunction fails with an EOF error because it tries to read the gzip header from an empty body. -
Implemented the fix: Added checks in the
decodeBodyfunction ininternal/output/response.goto:- Check if the status code is 204 (No Content), 304 (Not Modified), or 1xx (Informational) - these should never have a body according to RFC 7230-7235
- Check if the Content-Length header is 0 - if so, skip decompression
- Both checks prevent the
reg.Decompresscall from being made on empty bodies
-
Added a helper function
shouldSkipBodyto determine if an HTTP response should have no body according to RFC 7230-7235. -
Added comprehensive tests in
internal/output/response_204_test.goto verify:
-
Assistant
Let me summarize the changes I made and then submit them.
Summary of changes:
- Modified
internal/output/response.goto add checks for HTTP status codes that should never have a body (204, 304, 1xx) and for Content-Length: 0 - Added a helper function
shouldSkipBodyto determine if a response should have no body - Added a new test file
internal/output/response_204_test.gowith comprehensive tests for the fix
All tests pass, including existing tests and new tests.
- Modified
Assistant
I need to check if the test file is also included in the changes before submitting.
Assistant
Now let me submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.