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's first see what files are present.
- Assistant
Let me explore the repository structure more broadly to understand the layout and then look at the specific error handling code mentioned in the stack trace.
- Assistant
Let me look at the error mentioned in the issue. The stack trace points to:
cli/request.go:568inMakeRequestAndFormat- The error is about parsing a response with HTTP status 204 (No Content) which returns an empty body.
Let me look at the relevant files.
- Assistant
The repo structure seems different from what the stack trace shows. Let me look at the internal directory.
- Assistant
Let me look at the request handling code. The stack trace mentions
cli/request.go:568andcli/cli.go:849, but those might be from an older version. Let me find the relevant code. - Assistant
Let me look at the request execution code where the response body is being parsed.
- Assistant
Let me look at the request execution code more carefully.
- Assistant
Let me search for "Parse response error" across the entire codebase.
- Assistant
Let me search more broadly for the error message pattern.
- Assistant
Let me search for where the response body is being read and decoded.
- Assistant
Let me look at the response handling code, especially around where204 No Content is handled.
- Assistant
Now let me look at the HTTP handling code, specifically where response bodies are read and parsed.
- Assistant
Let me look at the actual response parsing code in http.go more carefully. The issue is that when a 204 No Content response is returned with a Content-Encoding: gzip header, but no body, the decompression fails with EOF. Let me look at the code around line 667 and related.
- Assistant
Let me look at the content decompression code to see how it handles empty bodies.
- Assistant
Let me look at the Decompress function in the registry to understand how it handles empty responses.
- Assistant
Now I understand the issue. When a 204 No Content response comes with a
Content-Encoding: gzipheader, the decompressor tries to read from the (empty) body and fails with EOF. Let me trace the full response handling flow to understand where the fix should go. - Assistant
Let me look at how the response is being handled overall - particularly the code that reads the body and processes it.
- Assistant
Let me look at the full request execution flow.
- Assistant
Let me look at the request execution code more carefully, focusing on where the response body is parsed.
- Assistant
Let me look at the main flow in the http.go file around where the response body is read.
- Assistant
Let me look at the
normalizeHTTPResponsefunction. - Assistant
The
normalizeHTTPResponsedoesn't seem to be in http.go. Let me search for it elsewhere. - Assistant
Let me look at the
normalizeHTTPResponsefunction. - Assistant
Let me look at the
output.Normalizefunction. - Assistant
Let me look at the
Normalizefunction in the output package. - Assistant
Now I understand the issue. The
decodeBodyfunction tries to decompress the response body using gzip when the server sendsContent-Encoding: gzip, but for a 204 No Content response, the body is empty. The gzip reader fails when trying to read from an empty body.Let me look at the Decompress function to understand how it handles empty bodies.
- Assistant
Let me check what
gzip.NewReaderdoes with an empty reader: - Assistant
Let me set up the Go environment properly.
- Assistant
Let me check how the issue manifests more precisely by looking at the
decodeBodyfunction again and the test file: - Assistant
Let me check existing tests for 204 responses:
- Assistant
Let me look at the existing test to understand the expected behavior for 204:
- Assistant
Now I understand the issue clearly. The problem is:
- Server returns HTTP 204 No Content with
Content-Encoding: gzipheader - The body is empty
- The code tries to decompress using
gzip.NewReader()which fails because there's no valid gzip data (it's empty) - This causes an EOF error
The fix should be to handle empty bodies gracefully when decompression is requested. Let me look at the
Decompressfunction and thedecodeBodyfunction to understand where the best fix would be. - Server returns HTTP 204 No Content with
- Assistant
Let me look at how gzip.NewReader behaves with empty bodies:
- Assistant
Now I understand the issue completely. When a 204 No Content response has
Content-Encoding: gzipheader but an empty body, the gzip decompressor fails because it tries to read gzip headers from an empty stream.Let me look at how the response body length is available:
- Assistant
Let me check the existing tests to understand how 204 responses are tested:
- Assistant
Let me look at
makeRespto understand how tests create responses: - Assistant
Let me look at the makeResp function to understand how test responses are created.
- Assistant
Now I understand the issue completely. The problem is in the
decodeBodyfunction. When a 204 No Content response comes withContent-Encoding: gzipheader but an empty body, the code tries to decompress the gzip body. Thegzip.NewReaderfails with EOF because there's no valid gzip data to read.Let me look at the
rawResponseBodyBytesfunction as well: - Assistant
Now I understand the root cause. The issue is that when a 204 No Content response comes with
Content-Encoding: gzipheader but an empty body, thegzip.NewReaderfails with EOF because there's no valid gzip data to read. The fix should check if the response body is empty before attempting decompression.Let me first create a test to reproduce the error:
- Assistant
Good, I've confirmed the issue.
gzip.NewReaderfails with EOF when given an empty body. Now let me think about the best fix location.The issue is that
gzip.NewReader()returns an error (EOF) when the input body is empty. The fix should handle this gracefully. Let me look at where the decompression happens and decide on the best place to fix it.Let me examine the
decodeBodyfunction more carefully and understand the flow: - Assistant
I need to go back to the /restish directory.
- Assistant
Now I understand the full picture. The issue is in the
decodeBodyfunction. When a 204 No Content response comes withContent-Encoding: gzipheader but an empty body:- The code calls
reg.Decompress(encoding, resp.Body)with encoding="gzip" - The gzip decompressor tries to create a gzip reader on the empty body
gzip.NewReader()fails with EOF because there's no valid gzip header4. This error propagates up and causes the "Parse response error: EOF"
The fix should be to check if the response body is empty before attempting decompression. Let me also check the other places where decompression happens:
- The code calls
- Assistant
Now I need to decide on the best fix location. There are three places where
Decompressis called:internal/output/response.go-decodeBodyfunction (line 84)internal/cli/http.go-rawResponseBodyBytesfunction (line 667)internal/cli/http.go-decompressedResponseBodyfunction (line 689)
The most elegant fix would be to handle this at the
Decompresslevel in the registry by making it handle empty bodies gracefully. Let me check if we can detect empty bodies before attempting decompression: - Assistant
Let me look at the full decodeBody function to understand the logic:
- Assistant
Now I understand the full picture. The issue is:
- Server returns 204 No Content with
Content-Encoding: gzipheader but empty body decodeBodycallsreg.Decompress("gzip", resp.Body)gzip.NewReader()fails with EOF because it can't read the gzip header from an empty body
The fix should check if the response body is empty before attempting decompression. Let me implement the fix.
- Server returns 204 No Content with
- Assistant
Now I understand the issue. The problem is in the
decodeBodyfunction. When a 204 No Content response comes withContent-Encoding: gzipheader but an empty body,gzip.NewReader()fails with EOF because it can't read the gzip header from an empty stream.The fix should check if the response body is empty before attempting decompression. Let me implement the fix:
- Assistant
Let me use the proper edit command format:
- Assistant
Now let me verify the fix compiles and run the existing tests:
- Assistant
I need to set GOPATH and GOMODCACHE properly.
- Assistant
Let me check what Go environment is available:
- Assistant
The issue is that the Go environment variables aren't set properly. Let me try setting them explicitly.
- Assistant
The fix compiles. Now let me also check if the same issue exists in the other decompression call sites. Let me look at when
rawResponseBodyBytesanddecompressedResponseBodyare called: - Assistant
Let me also fix the same issue in
rawResponseBodyBytesanddecompressedResponseBody: - Assistant
I need to also fix these two functions to handle the same case. Let me fix
rawResponseBodyBytes: - Assistant
Let me trace through the flow for a 204 response to understand all the code paths:
- Assistant
Let me check what
responseMetadataOnlydoes: - Assistant
Let me look at
responseMetadataOnly: - Assistant
Let me look for "Decoding response from" log messages:
- Assistant
Let me check if
canPrintWithoutResponseBodyhandles 204 properly: - Assistant
Let me look at how the tests currently handle204 responses:
- Assistant
Let me think about a better approach. The issue is that
gzip.NewReader()fails with EOF when given an empty body. The fix I applied checksresp.ContentLength == 0, but this might not always be set correctly for all HTTP/2 responses.Let me look at a more robust approach. I should handle the case where the body is empty before attempting decompression. Let me check how Go's HTTP client handles empty bodies:
- Assistant
Let me think about a more robust approach. The issue is that some servers send
Content-Encoding: gzipwith empty bodies on204 responses. My current fix checksContentLength == 0, but this might not always be reliable. Let me implement a more robust solution that handles the empty body case by checking if the body has content before attempting decompression: - Assistant
Let me think about this more carefully. The
ContentLengthcheck might not be sufficient for all cases. Let me look at how HTTP/2 handles empty bodies: - Assistant
Wait, I need to think about this more carefully. The
ContentLengthmight be-1for HTTP/2 responses without a Content-Length header, even though the body is empty. Let me look at a more robust approach.Let me check what the HTTP/2 response actually has for
ContentLength: - Assistant
Actually, let me reconsider. The
ContentLength == 0check might not be sufficient because some servers might not set Content-Length correctly. Let me implement a more robust fix that handles the empty body case by checking if the body is empty before attempting decompression. - Assistant
Actually, let me reconsider the approach. The
ContentLengthcheck might not work for all cases. A more robust approach would be to handle the empty body case before attempting decompression, or to handle the decompression error gracefully when the body is empty. Let me implement a fix that handles this at the decompression level: - Assistant
Let me use the terminal edit command properly:
- Assistant
Now let me also check if the error might be wrapped. Let me look at how gzip.NewReader returns errors:
- Assistant
Good,
err == io.EOFworks. But I should useerrors.Isto be more robust. Let me check the imports: - Assistant
Let me search for the "Decoding response from" log message:
- Assistant
Let me also apply the same fix to the other decompression functions in http.go. First, let me fix
rawResponseBodyBytes: - Assistant
Wait, let me reconsider. Let me search for "Decoding response from" to find the exact log message:
- Assistant
Let me apply the same EOF handling fix to the other two functions in http.go:
- Assistant
Now let me also fix
decompressedResponseBody: - Assistant
Now let me also fix
decompressedResponseBody. This returns anio.ReadCloser, so for the EOF case we need to return an empty reader: - Assistant
Let me also check the stream.go file which also has a decompression call:
- Assistant
Let me check all places where Decompress is called:
- Assistant
Now let me verify the build and run the tests:
- Assistant
Good, the build succeeds. Now let me run the existing tests:
- Assistant
My
ContentLength == 0check is too broad - it's catching normal responses too. Let me look at those tests: - Assistant
The
ContentLengthcheck is too broad -makeRespdoesn't set Content-Length, so its default is 0. Let me revert theContentLength == 0check and instead rely on the EOF error handling: - Assistant
The
ContentLength == 0check is too broad because Go's http.Response hasContentLengthdefault to 0 when not set. Let me revert to just using the EOF handling: - Assistant
Now let me run the tests again:
- Assistant
All tests pass. Let me also run the broader test suite to make sure nothing else is broken:
- Assistant
Let me run the full test suite for the relevant packages:
- Assistant
Let me also run the CLI tests to make sure my changes to http.go don't break anything:
- Assistant
All tests pass. Now let me also run the full test suite to make sure everything is working:
- Assistant
All tests pass. Let me now also look at the streaming code path to see if there's a similar issue:
- Assistant
Let me check if there are any other decompression calls I might have missed:
- Assistant
Good, all three decompression call sites are covered. Now let me also check the streaming code to see if it handles decompression:
- Assistant
Let me also check the dispatch.go file:
- Assistant
Let me also look at the request.Do function to see if there are any other places where decompression happens:
- Assistant
Good. Now let me run the full test suite one more time to make sure everything is working:
- Assistant
All tests pass. Let me verify the changes I've made by looking at the diff:
- Assistant
Now let me write a quick test to verify that the fix works for the specific case mentioned in the issue:
- Assistant
Let me write a proper test in the existing test file instead:
- Assistant
I can't add tests. Let me write a temporary script to verify the fix works instead:
- Assistant
Let me check how the test registry is set up:
- Assistant
I see,
testRegistryis defined in the test file, not exported. Let me update my temporary test file: - Assistant
The fix works for the 204 with gzip content encoding case. Now let me clean up the temporary test file:
- Assistant
Let me run the full test suite one more time to confirm everything is working:
- Assistant
All tests pass. Let me verify the final diff one more time:
- Assistant
The changes look correct and minimal. Let me submit the solution:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.