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
I'll start by exploring the repository structure and understanding the codebase, then reproduce the issue.
Assistant
Let me make a single call first.
Assistant
Let me look at the request.go file mentioned in the stack trace.
Assistant
Let me find the request.go file.
Assistant
The structure has changed. Let me look at the internal/cli directory.
Assistant
The structure has been reorganized. Let me search for the
MakeRequestAndFormatfunction mentioned in the stack trace.Assistant
The function name has changed. Let me search for "Parse response error" which is in the log.
Assistant
No results. The strings might have changed. Let me search for partial strings.
Assistant
Let me search for related terms.
Assistant
Let me look at the http.go file around the relevant lines, especially the body handling.
Assistant
Let me continue reading to find where it formats the response.
Assistant
Let me look at the
normalizeHTTPResponsefunction where the body is parsed.Assistant
Let me look at the
normalizeHTTPResponsefunction and thecanPrintWithoutResponseBodyfunction.Assistant
Let me look at the
canPrintWithoutResponseBodyand thenormalizeHTTPResponsefunctions.Assistant
Now let me look at the
normalizeHTTPResponsefunction in request_exec.go.Assistant
Now let me look at the
output.Normalizefunction in the output package.Assistant
This is interesting. The
decodeBodyhandles emptyrawbut the issue is about a 204 response withContent-Encoding: gzipand an empty body. Let me look at theDecompressfunction and reproduce the issue.Assistant
Now I understand the flow. Let me write a reproduction test to confirm the issue with an empty body and
Content-Encoding: gzip.Assistant
The
gzip.NewReaderover an empty stream returnsio.EOFimmediately. So indecodeBody,reg.Decompressreturns(nil, io.EOF), which produces the "decompressing response: EOF" error. Let me check thedecompressedResponseBodyfunction used in the streaming/raw path to understand how the codebase handles decompression.Assistant
Let me look at existing tests around 204 responses and decompression to understand the test structure.
Assistant
Let me look at the
responseBodyReadErrorfunction and search the tests for decompression-related scenarios.Assistant
Let me look at the test helpers for creating responses, especially gzip ones.
Assistant
Let me look at the rest of the test helpers.
Assistant
Let me check what
printBoundedResponseandincludesResponseBodydo, to understand the default path.Assistant
Now I understand the flow. The default printSpec includes a rendered body, so a 204 with
Content-Encoding: gzipand empty body goes throughnormalizeHTTPResponse→decodeBody, which fails becausegzip.NewReaderreturnsio.EOFon an empty stream. Let me write a reproduction test to confirm.Assistant
Let me set up the Go environment variables properly.
Assistant
I've reproduced the issue: "decompressing response: EOF". Now let me check the Go version and the brotli/deflate behavior for empty streams to design a robust fix.
Assistant
Let me test how brotli and deflate handle empty streams to design a robust fix.
Assistant
Let me check the brotli/deflate behavior and search for any existing handling of bodyless responses (204, 304, HEAD).
Assistant
Let me look at
handleMislabeledJSONLinesand the streaming detection to ensure a peek-based fix won't interfere.Assistant
handleMislabeledJSONLinesonly runs whenMaxItems > 0, so the default path goes straight tonormalizeHTTPResponse→decodeBody. Confirmed.Now let me look at the imports in response.go and the exact
decodeBodycode to plan the edit.Assistant
Let me check the imports in http.go.
Assistant
I've confirmed the root cause. The fix needs to detect an empty body before attempting decompression, since decompressing an empty stream fails (gzip returns
io.EOF; brotli/deflate/zlib return unexpected EOF — so an error-based check can't distinguish empty from truncated). I'll add a sharedPeekBodyEmptyhelper and use it in the three body-reading functions.Let me start by editing
response.goto add imports and the helper, and to updatedecodeBody.Assistant
Now let me update the imports in response.go.
Assistant
Now let me update the
decodeBodyfunction to detect an empty body before decompression.Assistant
Now let me add the
PeekBodyEmptyhelper to response.go. I'll add it right after thedecodeBodyfunction.Assistant
Now let me update
rawResponseBodyBytesanddecompressedResponseBodyin http.go.Assistant
Now let me verify the build compiles.
Assistant
Build succeeds. Now let me run my reproduction test.
Assistant
The fix works. Now let me expand the reproduction test to cover the piped (raw) path and brotli/deflate encodings, plus a truncated-body case (to make sure we still error on actual corruption).
Assistant
There's already a
gzipByteshelper. Let me rename mine.Assistant
All reproduction tests pass, including verifying that truncated bodies still error (we don't mask real corruption). Now let me run the existing test suites for the affected packages.
Assistant
A test failed. Let me look at
TestSSEReadErrorFailsCommand.Assistant
The failure is because my unconditional peek in
decompressedResponseBodysurfaces read errors during the peek (for identity-encoded SSE streams) instead of during the stream read. The peek is only needed when aContent-Encodingis applied. Let me make the peek conditional onContent-Encodingbeing set in all three functions, which also minimizes behavior change for identity responses.Let me first check for any existing tests involving encoding + broken bodies.
Assistant
Now let me look at the mislabeled json lines test with gzip encoding (line ~555-565).
Assistant
Now I'll refine the three functions so the peek only happens when a
Content-Encodingis applied. This avoids the SSE streaming regression (where identity-encoded stream read errors must surface during consumption). Let me view the current state of the edited functions.Assistant
Let me refine
decodeBodyto only peek when an encoding is applied.Assistant
Now let me refine
rawResponseBodyBytesanddecompressedResponseBodyin http.go to make the peek conditional.Assistant
Let me build to catch any compile errors.
Assistant
As expected. Let me fix
rawResponseBodyBytesto declareerr. Let me use:=properly. Let me changevar empty boolandbody, empty, err =to declare err.Let me edit to use a clean approach: declare
var empty boolandvar err error.Assistant
Build succeeds. Now let me run the previously failing streaming test and my repro tests.
Assistant
All passing. Now let me run the full cli and output test suites.
Assistant
All passing. Let me run the full test suite to ensure nothing else broke.
Assistant
All tests pass. Let me also verify with a real
httptestserver (real HTTP transport) to confirm the exact scenario from the issue works end-to-end, since my repro used a synthetic response.Assistant
The real HTTP transport scenario works end-to-end. Now let me clean up the temporary test files I created before submitting.
Assistant
Only the two source files are modified. Let me review the final diff.
Assistant
The diff looks clean. Let me verify formatting with
gofmt.Assistant
Both files are properly formatted. Let me run
go vetto be safe.Assistant
Everything is clean. Let me do a final uncached run of the affected test packages to confirm.
Assistant
All tests pass. Let me do a final verification of the complete diff once more and confirm no stray temp files remain.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.