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.code$ 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:codeERROR: Parse response error ERROR: Caught error: EOFHere is the full log:
code - Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first see what's in the root directory.
- Assistant
Let me explore the main repo structure and specifically look at the error location from the stack trace.
- Assistant
The error occurs in
cli/request.go:568. Let me look at the main CLI package, which seems to be in aclidirectory. Let me check the internal directory. - Assistant
Let me look at the cli directory which likely contains the request handling code where the error occurs.
- Assistant
The stack trace from the issue shows the error happens in
cli/request.go:568withMakeRequestAndFormat. Let me look at the relevant files, particularly around request handling and response parsing.The error trace shows:
codegithub.com/danielgtaylor/restish/cli.MakeRequestAndFormat(0x1052d4830?) /home/runner/work/restish/restish/cli/request.go:568 +0x118But in the current repo, there doesn't seem to be a
cli/request.go- instead there'srequest_exec.go. Let me check the request handling files. - Assistant
Let me look at the
http.gofile since the stack trace showsMakeRequestAndFormatand the current code hasnormalizeHTTPResponse. Let me also look atoutput.Normalizesince that's likely where the response body parsing happens. - Assistant
The stack trace references an older version of the code (v0.20.0). Let me look at the current version's response handling code, particularly in the
outputpackage andhttp.go: - Assistant
The issue is about a 204 No Content response that contains a
Content-Encoding: gzipheader, but the body is empty. The client tries to decode the gzip body and fails with EOF because there's nothing to decompress.Let me look at the request/response handling code more carefully, specifically the part that handles decompression.
- Assistant
Let me look at the decompression and response normalization code to understand how gzip responses are handled.
- Assistant
So the issue is in the decompression step. When a 204 No Content response is received with a
Content-Encoding: gzipheader, the code tries to decompress an empty body, which causes an EOF error.Let me look at the
Decompressmethod in the content package: - Assistant
Let me look at the
Decompressmethod in the content registry and theNormalizefunction in the output package. - Assistant
Now let me look at the
output.Normalizefunction: - Assistant
Let me examine the Normalize function:
- Assistant
Now I understand the issue. Looking at the
decodeBodyfunction in/restish/internal/output/response.go:- It gets the
Content-Encodingheader (which isgzipfor the 204 response) - It tries to decompress the response body using the gzip decompressor
- The gzip decompressor fails with EOF because the body is empty
The problem is that for 204 No Content responses, the server may still send
Content-Encoding: gzipheader, but the body is empty. The gzip decompressor tries to read from an empty body and fails with EOF.The fix should be in the
decodeBodyfunction in/restish/internal/output/response.go. We need to handle the case where:- The response body is empty (or the status code indicates no content)
- The
Content-Encodingheader is set to something likegzip
We should skip decompression if the body is empty. But wait, let me also check the
Decompressfunction in the content package to see if it handles empty bodies.Looking at the
defaultGzipDecompressfunction, it callsgzip.NewReader(r), which will fail with EOF if the reader is empty.Let me look at the gzip decompress function:
- It gets the
- Assistant
Now I understand the issue clearly. The problem is in the
decodeBodyfunction in/restish/internal/output/response.go. When a server returns HTTP 204 No Content with aContent-Encoding: gzipheader (but empty body), the code tries to decompress the empty body with gzip, which fails with EOF.Let me also check the
rawResponseBodyBytesanddecompressedResponseBodymethods inhttp.gowhich have the same pattern: - Assistant
Now I understand the issue. When a server returns HTTP 204 (No Content) with a
Content-Encoding: gzipheader but an empty body, thedecodeBodyfunction tries to gzip-decompress an empty body, which fails with EOF. Let me trace the exact code path and create a fix.Let me first look at the test files to understand the existing test patterns:
- Assistant
Let me look at the existing tests for 204 responses:
- Assistant
Now I have a clear picture of the issue. Let me check the
defaultGzipDecompressfunction more carefully and understand the error: - Assistant
Let me try running this in the repository context where Go is available.
- Assistant
Now I have a clear picture of the issue:
- Server returns HTTP 204 No Content with
Content-Encoding: gzipheader - The response body is empty (expected for 204)
- The code tries to decompress using
gzip.NewReader()which fails withio.EOFbecause there's no gzip header to read
The fix should be in the
Decompressmethod to handle empty bodies gracefully. Let me implement the fix: - Server returns HTTP 204 No Content with
- Assistant
Now I understand the problem. Let me look at the
http.goto understand the full flow: - Assistant
Now I have a clear understanding of the issue. The problem is that when a server returns HTTP 204 No Content with a
Content-Encoding: gzipheader (but an empty body), the decompression tries to decompress an empty body which fails with EOF.The fix should be in the
Decompressmethod of the content registry to handle empty bodies gracefully. Let me implement the fix: - Assistant
Let me create a simple test to reproduce the issue first:
- Assistant
Let me write the test inside the proper test package:
- Assistant
Let me verify the issue reproduces with a test that has Content-Encoding: gzip on a 204:
- Assistant
I've reproduced the issue. Now let me implement the fix. The problem is in
decodeBodyin/restish/internal/output/response.go. The function tries to decompress the body before reading it, but when the body is empty and encoding is gzip,gzip.NewReaderfails with EOF.The fix: read the raw body first, and only decompress if there's content. Let me also fix the same pattern in
rawResponseBodyBytesanddecompressedResponseBodyinhttp.go. - Assistant
I see the issue. Let me look at the Decompress method and think about the best fix:
- Assistant
Now I understand the issue fully. The problem is in
decodeBody- it tries to decompress the body before reading it. When the body is empty (e.g., 204 No Content) but has aContent-Encoding: gzipheader,gzip.NewReaderon the empty body returns EOF.Let me implement the fix in
decodeBody: - Assistant
Let me try a different approach. I'll use the
opencommand to view the file and then useeditwith proper context. - Assistant
Let me view the rest of the decodeBody function.
- Assistant
Now I understand the issue clearly. Let me trace the flow:
- Server returns HTTP 204 No Content with
Content-Encoding: gzipheader but empty body decodeBodycallsreg.Decompress("gzip", resp.Body)whereresp.Bodyis emptygzip.NewReader(emptyBody)returnsio.EOFerror- The error propagates up as "decompressing response: EOF"
The cleanest fix is in the
Decompressmethod itself - it should handle empty readers gracefully. Let me implement the fix: - Server returns HTTP 204 No Content with
- Assistant
The
edittool seems confused. Let me use the--fileoption explicitly. - Assistant
Let me try using the edit command with --file option
- Assistant
Now let me test if this fix resolves the issue:
- Assistant
The fix resolves the issue. Now let me run all existing tests to make sure we didn't break anything:
- Assistant
Good, all content tests pass. Let me also run the output tests.
- Assistant
All tests pass. Let me also run the request tests and http tests to make sure nothing is broken:
- Assistant
All tests pass! Let me also run all the tests in the repository to make sure nothing is broken:
- Assistant
All tests pass across the entire repository. Let me clean up the temporary test file I added:
- Assistant
Let me run the tests one more time to make sure removing the temp test file doesn't break anything:
- Assistant
Let me also check the
rawResponseBodyBytesanddecompressedResponseBodymethods inhttp.gofor the same issue: - Assistant
Both
rawResponseBodyBytesanddecompressedResponseBodycallc.content.Decompress(), which is the method we just fixed. So the fix applies to all code paths. Let me verify the final state of the changes: - Assistant
Let me run the full test suite one final time to be sure:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.