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
Assistant
Now let me look at the request execution path to understand where parsing of response happens:
Assistant
Let me look for the
Verboselogger and the source of the error messages:Assistant
Now let me look at the http.go verbose output code:
Assistant
Now let me look at the request_exec.go file to find where the response is being parsed:
Assistant
Let me look at output.Normalize:
Assistant
The original error mentioned
Decoding response from gzipand the panic stack trace mentionedrequest.go:568(but those paths don't exist in the new code). Let me check more recent git log to see when this was changed:Assistant
Now let me check the Decompress function in content/registry.go to understand the gzip handling:
Assistant
Now let me check what happens when there's no body for status 204. Let me trace through the code to understand the issue.
When a 204 response comes back, the server says "Content-Encoding: gzip" but the body is empty. The decoder tries to read the gzip header but the body is empty, so
gzip.NewReader(r)returns anEOFerror.Let me reproduce this:
Assistant
I've reproduced the error. Now let me trace through the code to find where this happens in restish:
Assistant
I can see the issue clearly. In
decodeBody:- The
encodingis "gzip" reg.Decompress("gzip", resp.Body)returns a gzip reader (no error here sincegzip.NewReaderis lazy)- Then
io.ReadAll(io.LimitReader(reader, maxBytes+1))tries to read from the gzip reader, which triggers the actualgzip.NewReaderreading of the header. Since the body is empty, this returns anEOFerror.
This is the source of the issue. Let me verify by tracing through:
The original
gzip.NewReaderis lazy, but the read triggers the parsing of the gzip header (which expects at least 10 bytes). If the body is empty, it returns EOF.Let me also check if there's any 204 handling:
- The
Assistant
Now let me check the related test in output_test.go:
Assistant
Now I understand the issue. Let me check the design documentation to understand the design rationale:
Assistant
Now I understand the design. Let me check the relevant area more carefully. The issue is that the
decodeBodyfunction reads from the gzip decompressed body when the body is empty, which causes anEOFerror fromgzip.NewReader.Looking at
decodeBodymore carefully:func decodeBody(resp *http.Response, reg *content.Registry, maxBytes int64) (decoded any, raw []byte, err error) { encoding := resp.Header.Get("Content-Encoding") reader, err := reg.Decompress(encoding, resp.Body) if err != nil { return nil, nil, fmt.Errorf("decompressing response: %w", err) } defer reader.Close() // Read up to maxBytes+1 so we can detect a body that exceeds the limit. raw, err = io.ReadAll(io.LimitReader(reader, maxBytes+1)) ... }Assistant
Let me look at the relevant content/registry.go more carefully:
Assistant
Now let me check the original issue more carefully. The panic was at
request.go:568but our code hasdecodeBodyinresponse.go. Let me verify whatReadAllreturns when the body is empty:Assistant
So
gzip.NewReaderreturns an error immediately when there's no data. The error is "EOF".Now let me look at how
reg.Decompresshandles this:Assistant
OK, in this case
gzip.NewReaderreturns an error. Thedecompressfunction returns(*Reader, err). Let's see what the Decompress returns from the registry:Assistant
So
reg.Decompressreturns anEOFerror fromgzip.NewReaderwhen the body is empty. This is the source of the bug.Looking at
decodeBodyininternal/output/response.go:encoding := resp.Header.Get("Content-Encoding") reader, err := reg.Decompress(encoding, resp.Body) if err != nil { return nil, nil, fmt.Errorf("decompressing response: %w", err) }The bug: When the server returns a 204 with
Content-Encoding: gzipheader but no body,gzip.NewReaderreturns an EOF error because it can't read the gzip header (which requires at least 10 bytes).This is actually a server bug (per HTTP spec, 204 responses should not have Content-Encoding), but restish should handle this gracefully.
Let me look at how the original
request.gohandled this issue and check git history:Assistant
Assistant
Now let me decide on the fix approach. I'll modify
decodeBodyto handle the case where:- The response status indicates no body (204, 304)
- The Content-Length is 0
- The body is empty (regardless of Content-Encoding header)
Actually, the simplest and most robust fix is to attempt the decompression but treat an
EOFerror as an empty body. This is because:- If the body is empty, no decompression should be needed (the empty result is the same).
- A server sending
Content-Encoding: gzipwith an empty body is technically incorrect but should be handled gracefully.
Let me check the simplest fix - if the response body is empty (0 bytes), we should skip the decompression entirely. We can check this by trying to read 1 byte first:
Wait, actually, we already handle the case where
len(raw) == 0afterReadAll. So the issue is just that the ReadAll itself fails for gzip.Assistant
Good. The body is genuinely empty. So the issue is purely in the
gzip.NewReaderfailing on an empty stream.Now let me think about the right fix. Looking at the code flow:
decodeBodycallsreg.Decompress("gzip", resp.Body)Decompresscallsgzip.NewReader(resp.Body)which fails with EOF
Assistant
Now let me also think about the alternative: the fix could be at the
Decompresslevel. Let me check what other encodings do for empty bodies:Assistant
Assistant
Excellent! For 204 responses:
ContentLengthis 0Body == http.NoBody
Wait, but the original issue from Synadia Cloud shows:
DEBUG: Got response from server in 426.428041ms: HTTP/2.0 204 No Content Content-Encoding: gzipNo
Content-Lengthis shown in the response. Let me check what happens with HTTP/2.0 and 204 with no Content-Length:Assistant
OK so the issue is consistent. Let me also test with HTTP/1.1 since the original issue shows HTTP/2.0 but the Go test server uses HTTP/1.1:
Assistant
OK, so for 204 responses,
ContentLengthis 0 regardless of HTTP version. So we can check this.Now let me design the fix. The approach:
- At the start of
decodeBody: Check if the response is one that shouldn't have a body. If so, return early.
The check should be:
- Status code 204, 304, or 1xx (per HTTP RFC 7230 §3.3)
- ContentLength is 0 (explicit no body)
This is a clean, explicit check that doesn't require any complex buffering.
Let me look at the issue one more time to make sure I understand it:
In this case, it's expected to have an empty body. Nevertheless,
restishfails with the error:ERROR: Parse response error ERROR: Caught error: EOFSo the user expects an empty body, but restish fails. The fix should:
- Not fail on 204 responses with empty body
- Still work correctly for other cases
Let me now write the fix:
- At the start of
Assistant
Assistant
Now let me write the fix:
Assistant
Let me implement the fix now.
Assistant
Let me trace through where the verbose output of "Decoding" might come from in the current codebase:
Assistant
Now let me implement the fix. I'll add a check at the start of
decodeBodyto handle responses that have no body:Assistant
Let me try a different approach using a temporary file approach:
Assistant
Now let me verify the code compiles:
Assistant
Now let me write a test to reproduce the original issue and verify the fix:
Assistant
The fix works! The panic at the end is just my test script having a bug (passing nil instead of the raw). Let me fix my test:
Assistant
The fix works for the original issue. Now let me verify that the fix doesn't break the existing tests:
Assistant
Wait, there are test failures! Let me investigate:
Assistant
me check the
ContentLengthfield behavior in Go:Assistant
I see the issue - my ContentLength check is too aggressive because the test's
makeRespdoesn't set ContentLength, leaving it as 0 by default. Let me refine the check:Assistant
Let me update the fix to use the Content-Length header check instead, which is more precise:
Assistant
The tests pass. Let me verify the fix still works for the original issue:
Assistant
Test 3 is failing because my hand-crafted gzip bytes are wrong. That's expected, since I was just trying to verify that valid gzip bodies work. Let me fix the test:
Assistant
All tests pass. Now let me also test some edge cases:
Assistant
The 4th test failure is because I sent invalid brotli data. Let me run test 5 separately:
Assistant
Now let me also look at the actual
cli/http.goto see if there's a similar pattern:Assistant
Let me run the broader test suite to check for any regressions:
Assistant
All tests pass. Let me look at the final fix to make sure it's well-formed:
Assistant
Let me clean up the temporary reprotest directory:
Assistant
Now let me also run the integration tests to verify nothing is broken:
Assistant
All tests pass. Let me also verify that I haven't broken any of the existing tests by running them all:
Assistant
All tests pass. Let me also write a more thorough test script to verify the fix:
Assistant
All 10 tests pass. Let me clean up:
Assistant
Let me also check the file once more and verify the format:
Assistant
Let me re-read the design docs to make sure my fix is consistent:
Assistant
The fix is good. Let me also look at how the verbose output handles 204 responses to make sure there's no other issue:
Assistant
Let me also check
decompressedResponseBodysince the same issue might exist there:Assistant
Let me also fix
decompressedResponseBodysince it has the same issue:Assistant
Let me check how
decompressedResponseBodyis used in the streaming case (which might also have the issue):Assistant
Let me export the helper function and use it in
decompressedResponseBody:Assistant
Now let me update
decompressedResponseBodyto use the exported function:Assistant
Now let me check that this compiles and tests pass:
Assistant
All tests pass. Let me also run the integration tests:
Assistant
All tests pass. Let me also test the fix with a more comprehensive test:
Assistant
All tests pass. Let me clean up:
Assistant
Let me also look at the final state of the response.go and http.go:
Assistant
Let me also make sure the code is well-formatted:
Assistant
Let me run the full test suite one more time:
Assistant
All tests pass. Let me also verify the final diff:
Assistant
Let me run the specific tests for the output package and the cli package once more:
Assistant
All Normalize tests pass. Now let me look at the structure once more:
Assistant
The fix is clean and well-documented. Let me also run a final comprehensive test to make sure everything works:
Assistant
All tests pass. Let me now provide a comprehensive review of my fix and address the checklist:
Review of Changes
Let me think through the checklist items:
-
Reproducing the error: I reproduced the error with a test server that returns 204 with
Content-Encoding: gzipand an empty body. The error was confirmed -gzip.NewReaderreturns EOF when given an empty stream. -
Confirming my fix resolves the error: I verified that with my fix, the 204 with
Content-Encoding: gzipis now handled correctly, returning an empty body without error. -
Edge cases:
- ✅ 204 with
Content-Encoding: gzip(the original issue) - ✅ 204 with no body, no encoding (existing case)
- ✅ 304 with
Content-Encoding: gzipand no body - ✅ 1xx (100, 101) with
Content-Encoding: gzipand no body - ✅ 200 with valid gzip body (regression test)
- ✅ 200 with explicit
Content-Length: 0and
- ✅ 204 with
-
Assistant
Now let me provide a final summary:
Summary
The issue was that restish fails with
ERROR: Caught error: EOFwhen receiving an HTTP 204 No Content response that has aContent-Encoding: gzipheader but no body. This is incorrect per HTTP spec, but the Synadia Cloud API does this.Root Cause
In
internal/output/response.go, thedecodeBodyfunction callsreg.Decompress(encoding, resp.Body). When the encoding is "gzip", this callsgzip.NewReader(resp.Body), which fails with EOF when given an empty stream because it tries to read the gzip header.The same issue existed in
internal/cli/http.go'sdecompressedResponseBodyfunction, which is used for streaming responses, raw body output, and formatters.Fix
I added a helper function in that checks for responses that should not have a body:
Assistant
All tests pass. Now let me also verify with the original reproduction case one final time:
Assistant
The fix works. Let me also confirm the final state of changes:
Assistant
The diff is clean and focused. Let me address the checklist one final time:
Final Checklist Review
-
Reproducing the error: ✅ I successfully reproduced the error. The error occurs because
gzip.NewReaderreturns EOF when given an empty stream (e.g., a 204 response withContent-Encoding: gzipheader but no body). -
Confirming my fix resolves the error: ✅ I confirmed that with my fix, the 204 with
Content-Encoding: gzipis now handled correctly, returning an empty body without error. -
Edge cases:
- 1xx, 204, 304 responses with
Content-Encoding: gzip- handled ✅ - 200 with valid gzip body - regression test passes ✅
- 200 with explicit
Content-Length: 0- handled ✅ - 200 with valid JSON/text body - regression test passes ✅
- HEAD requests - handled ✅
- 1xx, 204, 304 responses with
-
Running existing tests: ✅ All existing tests pass (
go test ./...andgo test -tags=integration ./...).
Let me also look at the test file in the original code one more time to make sure I haven't missed any test cases:
-
Assistant
The existing test
TestNormalize_EmptyBodytests the 204 with no body case, and it still passes. My fix adds support for the additional case where the 204 hasContent-Encoding: gzipbut no body.Now let me submit the changes:
Assistant
All tests pass. The fix is complete. 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.