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
I'll start by exploring the repository structure to understand the codebase. Let me first check what's in the current directory.
- Assistant
Let me understand the issue first. When an HTTP response returns status 204 (No Content), the restish client fails with a parse error because it tries to decode the empty body. The error trace shows it panics in
cli/request.go:568in theMakeRequestAndFormatfunction.Let me look at the relevant code files.
- Assistant
Let me look at the error location in cli/request.go:
- Assistant
Let me find the actual file structure.
- Assistant
The cli package is under internal/cli/. Let me look for request.go
- Assistant
The repository seems to have been restructured. Let me find where the request handling is done now.
- Assistant
Let me look at the stack trace from the issue more carefully:
github.com/danielgtaylor/restish/cli.Run.func1() /home/runner/work/restish/restish/cli/cli.go:849 +0x68 ... 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 +0x814The key is the error "Parse response error" and "Caught error: EOF". The problem seems to be that when a 204 No Content response is received, restish tries to parse the response body (which is empty) and fails with EOF.
Let me look at the relevant code - the response handling code.
- Assistant
Let me look at the response handling. The issue is about parsing response when status is 204 (No Content) and the body is empty. Let me search for "Parse response error" or where the parsing happens.
- Assistant
The error message "Parse response error" comes from the old codebase. Let me search for the error handling code.
- Assistant
Let me look at the HTTP response handling code:
- Assistant
Let me look at the response handling code more carefully, particularly around where the body is read:
- Assistant
Let me look at the response handling flow around the body reading:
- Assistant
Let me look at the
normalizeHTTPResponsefunction and theresponseBodyAbsentfunction to understand how the body is handled. - Assistant
Let me look at the
normalizeHTTPResponseandresponseBodyAbsentfunctions: - Assistant
Let me search for the normalizeHTTPResponse function
- Assistant
Let me look at the normalizeHTTPResponse function in request_exec.go
- Assistant
The normalize function calls
output.Normalize. Let me look at that: - Assistant
The issue is about HTTP 204 (No Content) responses failing with "EOF" errors. Let me look at the
Normalizefunction in./internal/output/response.goto see how it handles the response body. - Assistant
Let me see the rest of the decodeBody function to understand how the body is decoded.
- Assistant
Now I understand the issue. Let me trace through what happens with a 204 No Content response with
Content-Encoding: gzip:- Server sends HTTP 204 with
Content-Encoding: gzipbut no body decodeBodycallsreg.Decompress(encoding, resp.Body)where encoding is "gzip"- The gzip decompressor tries to read from the empty body and gets EOF
Let me check the decompression logic:
- Server sends HTTP 204 with
- Assistant
Let me look at the Decompress function:
- Assistant
Let me look at the gzip decompress function:
- Assistant
Let me verify what happens with gzip.NewReader on an empty reader:
- Assistant
Let me set up the Go environment properly.
- Assistant
So
gzip.NewReaderon an empty body returnsEOF. This is the root cause. Let me trace the full flow:- Server returns 204 with
Content-Encoding: gzipheader but no body decodeBodytries to create a gzip reader on the empty bodygzip.NewReaderreturns EOF errordecodeBodyreturns the error- This causes the panic
Now let me look at the existing tests to understand the expected behavior:
- Server returns 204 with
- Assistant
Let me look at the http.go flow more carefully to understand exactly where the error occurs for a 204 response:
- Assistant
Let me look at the code around lines 260-310:
- Assistant
Now I understand the problem. When the server returns 204 with
Content-Encoding: gzipheader but no body,gzip.NewReader()fails with EOF. Let me write a test to reproduce the issue: - Assistant
Let me fix the test script.
- Assistant
Now I understand the root cause. When a 204 response comes with
Content-Encoding: gzipbut no body,gzip.NewReaderreturnsEOF. Let me also look at how 204 responses are handled in the current code: - Assistant
Let me look at how responseBodyAbsent works:
- Assistant
Now I understand the flow. Let me also look at how the existing tests handle response normalization:
- Assistant
Now I understand the issue. Let me also look at how the
decompressedResponseBodyfunction handles this case: - Assistant
Now I understand the issue. When a 204 No Content response comes with a
Content-Encoding: gzipheader but no body,gzip.NewReader()returnsEOFimmediately because it tries to read the gzip header from an empty body. This happens indecodeBodyinresponse.go.Let me also check the existing tests:
- Assistant
Let me look at the existing tests to understand what might break:
- Assistant
Let me look at the test helper
useJSONResponse: - Assistant
Let me find the useJSONResponse helper.
- Assistant
Let me look at how the test handles 204 responses:
- Assistant
Now let me look at the 204 test with explicit body-free output:
- Assistant
Let me look at the
useJSONResponsefunction: - Assistant
Now I understand the problem clearly. When the server returns a 204 No Content response with
Content-Encoding: gzipheader but an empty body,gzip.NewReader()returnsEOFwhen trying to create the gzip reader because it needs to read the gzip header. The error propagates up and causes the crash.The fix should be in the
decodeBodyfunction to handle empty bodies gracefully. I'll use abufio.Readerto peek at the body before attempting decompression. Let me implement the fix: - Assistant
Now I'll implement the fix. The key change is in the
decodeBodyfunction to handle empty bodies before attempting decompression: - Assistant
Let me use the correct syntax for the edit command.
- Assistant
Let me check the file after the edit.
- Assistant
Now I need to modify the
decodeBodyfunction to handle the case where the body is empty but Content-Encoding is set. The fix should be to check if the body is empty before attempting decompression.Let me implement the fix:
- Assistant
Let me try using the correct syntax:
- Assistant
Let me use a different approach:
- Assistant
Let me check the result:
- Assistant
Good. Now let me also fix the same issue in
rawResponseBodyBytesanddecompressedResponseBodyinhttp.go: - Assistant
Now I need to also fix
rawResponseBodyBytesanddecompressedResponseBodywhich also callDecompressand would have the same issue: - Assistant
Now I need to make sure
bufiois imported in thehttp.gofile: - Assistant
I need to add
bufioto the imports: - Assistant
Let me also check if the
defaultDeflateDecompressfunction in registry.go has the same issue: - Assistant
Now let me also check the
defaultDeflateDecompressfunction - it usesbufio.NewReaderinternally, which might have the same issue with empty bodies: - Assistant
Let me also check what happens with brotli:
- Assistant
Let me fix the test script and also test the deflate case (which seems to work differently).
- Assistant
Good - all decompressors (gzip, deflate, brotli) have issues with empty bodies. My fix handles all of them by peeking at the body before attempting decompression.
Let me verify the fix compiles:
- Assistant
The code compiles successfully. Now let me run the existing tests:
- Assistant
Let me continue checking the test results:
- Assistant
All output tests pass. Let me now run the CLI tests:
- Assistant
Let me run the full CLI test suite:
- Assistant
All normalize tests pass. Let me run the broader test suite:
- Assistant
All tests pass. Let me also run the content registry tests:
- Assistant
Let me run the full test suite:
- Assistant
All tests pass. Now let me write a quick test to verify the fix works for the specific issue:
- Assistant
Let me create the test within the package:
- Assistant
The fix works correctly for all cases. Now let me write an integration test within the package to verify the actual Normalize function works:
- Assistant
Let me create a test file within the package instead:
- Assistant
Wait, the instructions say I should NOT add new tests. Let me remove that test file:
- Assistant
Let me verify the fix works using a test script I'll remove later. Let me also create a temporary test:
- Assistant
I need to find how to create a content.Registry. Let me check.
- Assistant
The function is
content.New()notcontent.NewRegistry(). Let me update the test file. - Assistant
The tests weren't found. Let me check if the file exists:
- Assistant
The regex pattern seems not working. Let me try a different approach.
- Assistant
The issue is that
content.New()doesn't have decompressors registered. Let me check how to get a registry with all encodings: - Assistant
I need to use
content.Default()instead ofcontent.New(). Let me update the test file. - Assistant
All tests pass. Now let me remove the temporary test file and run the full test suite:
- Assistant
All tests pass. Let me verify the final state of my changes:
- Assistant
Let me run the tests once more without cache to be absolutely sure:
- Assistant
All 25 test packages pass. Let me verify the final state of the modified files one more time:
- Assistant
Let me also check the
edit.gowhich callsnormalizeHTTPResponse: - Assistant
Let me also check other callers of normalizeHTTPResponse:
- Assistant
All callers of
normalizeHTTPResponsego throughdecodeBodyinresponse.go, which is where I made the primary fix. TherawResponseBodyBytesanddecompressedResponseBodyfunctions inhttp.goalso needed fixes as they callDecompressdirectly.Let me verify no other direct
Decompresscalls were missed: - Assistant
All three places where
Decompressis called have been fixed. Let me do a final review of all changes: - Assistant
Let me run the full test suite one final time:
- Assistant
Let me also run the tests one more time with -count=1 to ensure they're not cached:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.