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 analyze the issue:
- The user is reporting that
restishfails when a DELETE API returns HTTP 204 (No Content) with an empty body. - The error is "Parse response error" with "EOF" - this suggests the code is trying to parse an empty response body as some format (JSON, etc.) and failing.
Let me start by exploring the repository structure to understand how responses are handled.
- The user is reporting that
Assistant
Let me look at the cli/request.go file mentioned in the stack trace, since that's where the error occurs.
Assistant
The cli directory doesn't exist at the root level. Let me find where the cli package is.
Assistant
Let me look at the cli/request.go file mentioned in the stack trace. The error happens at
cli/request.go:568andcli/operation.go:142.Assistant
I don't see a "request.go" file. Let me look at the operation.go or other relevant files. The stack trace mentions
cli/operation.go:142andcli/request.go:568. Since the files are now in/restish/internal/cli/, the structure has changed. Let me look for operation-related code and request handling.Assistant
Let me search for where responses are parsed and the error handling around it:
Assistant
The grep returned an error, which means "Parse response" isn't found in that directory. Let me search more broadly. The stack trace shows the error coming from
cli/request.go:568but in the current codebase, that file doesn't exist at that path. Let me look more broadly.Actually, let me re-read the stack trace more carefully. It says:
github.com/danielgtaylor/restish/cli.MakeRequestAndFormatatcli/request.go:568github.com/danielgtaylor/restish/cli.Operation.command.func1atcli/operation.go:142
The error is "Parse response error" and "Caught error: EOF". Let me search for where this error message is generated in the codebase.
Assistant
Let me look at the cli.go file and the http.go file to understand how responses are handled. The error "Parse response error" might be in the output or formatting layer.
Assistant
Let me look at the http.go file to understand response handling:
Assistant
Let me look at the normalizeHTTPResponse function:
Assistant
Let me look at the normalizeHTTPResponse function and surrounding code to understand how it handles response bodies.
Assistant
Let me look at the normalizeHTTPResponse function to understand how it handles response bodies.
Assistant
Now let me look at the
output.Normalizefunction:Assistant
Let me look at the decompress functionality and where the "Decoding response from gzip" message comes from:
Assistant
Now I see the issue. The problem is in the decompress/gzip handling. When a 204 response has
Content-Encoding: gzipbut an empty body, the gzip reader will try to read the gzip header from an empty body and fail with an EOF error.Let me look at the
defaultGzipDecompressfunction more closely, and see how it's called.Actually, looking at the debug log:
DEBUG: Decoding response from gzip ERROR: Parse response error ERROR: Caught error: EOFThis suggests the gzip decompress is being attempted. The
Content-Encoding: gzipheader is present but the body is empty (because it's a 204 response). The gzip reader fails when trying to decompress an empty body.Assistant
The grep command returned no matches, which means "Decoding response from gzip" isn't in the Go source code itself - it must be coming from somewhere else, perhaps from a log message in the decompress function.
Wait, I didn't actually execute the command. Let me run it again.
Assistant
The user is waiting for my response. I need to search for "Decoding response" in the codebase to find where the debug message comes from. Let me run the grep command again.
Assistant
The grep returned empty, so "Decoding response from gzip" is not in the source code. It might be from a different version. Let me focus on the actual issue: HTTP 204 responses with gzip content-encoding causing EOF errors.
Let me look at how decompression is handled:
Assistant
Now I understand the issue. When a 204 response has
Content-Encoding: gzipbut an empty body, the gzip reader tries to decompress empty data and fails with EOF. Let me examine thedecodeBodyfunction inresponse.goto implement the fix.The issue is in
/restish/internal/output/response.gowheredecodeBodytries to decompress a body that has a Content-Encoding header but is actually empty (as expected for 204 responses).Let me first create a test script to reproduce the issue:
Assistant
Let me create a test to reproduce the issue first, then fix it.
Assistant
Let me set up Go properly first:
Assistant
Let me check if there's a go.mod file and set up the environment properly.
Assistant
The module is
github.com/rest-sh/restish/v2. Let me try running the test script with proper GOPATH setup, or better yet, let me write a test file inside the test directory.Assistant
I can't import internal packages from outside. Let me create a test within the module structure instead:
Assistant
Now let me run the test to confirm the issue:
Assistant
The environment variables for Go cache and GOPATH are not set. Let me set them and try again.
Assistant
Let me check how to properly create a content registry:
Assistant
The test is failing because
content.NewRegistrydoesn't exist - it should becontent.New(). Let me fix the test file and run it again.Assistant
I need to run the test to confirm the issue exists. Let me try running the test with the proper Go environment variables.
Assistant
The test confirms the issue. The error is:
decompressing response: unsupported Content-Encoding "gzip"The problem is in the
decodeBodyfunction in/restish/internal/output/response.go. When the response body is empty (like for a 204 response), but has aContent-Encoding: gzipheader, the decompressor tries to read from an empty body and fails.Let me fix this by checking for an empty body before attempting to decompress:
Assistant
Now I understand the issue. The
decodeBodyfunction tries to decompress the body even when it's empty (like for 204 responses). The fix should check if the body is empty before attempting decompression. Let me modify thedecodeBodyfunction:Assistant
I need to modify the
decodeBodyfunction to handle the case where the body is empty but has a Content-Encoding header. The fix is to check if the body is empty before attempting decompression.Assistant
The tool call format is incorrect. I need to use the correct format for the edit command.
Assistant
Let me look at the exact format needed for the edit command:
Assistant
Let me try a different approach - I'll use sed to replace the function:
Assistant
Let me write the fix using a different approach - I'll create a script that modifies the file properly.
Assistant
The fix has been applied. Let me verify the changes and run the test:
Assistant
Now let me run the test to verify the fix works:
Assistant
Both tests pass. Now let me run all the existing tests in the output package to ensure I haven't broken anything:
Assistant
The tests are passing. Let me continue to see the full output.
Assistant
All tests in the output package pass. Now let me run tests for related packages that might use the Normalize function:
Assistant
Let me run tests in the cli package to make sure nothing is broken:
Assistant
All CLI tests pass. Let me also verify the content package tests pass, since we're now decompressing differently:
Assistant
All tests pass. Let me add more edge case tests to make sure the fix handles all Content-Encoding scenarios:
Assistant
Let me run the updated tests to make sure all edge cases pass.
Assistant
Excellent! All tests pass including my new edge case tests. Let me also check if there are similar decompression issues in other parts of the codebase, particularly in the http.go file mentioned in the stack trace.
Assistant
Let me check those usages in http.go to see if they might have similar issues with 204 responses:
Assistant
Let me examine whether the
rawResponseBodyBytesanddecompressedResponseBodyfunctions in http.go need similar fixes for empty bodies:Assistant
These functions in http.go might have the same issue. Let me check if they need fixing too by looking at how they handle empty bodies.
Assistant
Now let me verify the changes compile and run the tests:
Assistant
The
bytesimport wasn't added properly. Let me check and fix it:Assistant
The
bytesimport wasn't added because the script was looking for"bufio"but the import is in a different position. Let me add it manually:Assistant
Let me check if the import was added correctly and try to build again.
Assistant
Good, the
bytesimport is now added. Let me try building again:Assistant
The build succeeded. Let me verify the changes in the http.go file and run all tests:
Assistant
The changes look correct. Now let me run all the tests to verify everything works:
Assistant
Let me also run the full test suite to make sure nothing is broken:
Assistant
All tests pass. Let me verify the complete diff to ensure the changes are correct:
Assistant
All tests pass. Let me run the full test suite one more time to confirm everything is working:
Assistant
All tests pass. Let me run tests without cache to confirm the fix works end-to-end:
Assistant
All tests pass. Let me verify the test file I created is appropriate and then submit:
Assistant
Let me verify the test file content:
Assistant
All tests pass and the fix is complete. Let me verify the git status one more time and then submit:
Assistant
I have successfully fixed the issue where HTTP 204 (No Content) responses were failing with "EOF" errors when the server sent a
Content-Encoding: gzipheader with an empty body.Summary of Changes
Problem
When a DELETE API returns HTTP 204 with an empty body but includes a
Content-Encoding: gzipheader,restishwas attempting to decompress an empty body, which caused a decompression error.Solution
Modified the response body handling code to check for empty bodies before attempting decompression, rather than attempting to decompress first and then checking if the body is empty.
Files Changed
-
internal/output/response.go- ThedecodeBodyfunction now reads the body first, returns early if empty, and only attempts decompression when there's actual content to decompress. -
internal/cli/http.go- Applied similar fixes to:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.