-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat(main): add flushable writer for HTTP responses #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds a utility function to retrieve a flushable writer from the http.ResponseWriter. This allows flushing the response after writing each chunk of data, ensuring timely delivery to the client, especially in tarpit scenarios. Closes #84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a utility to obtain a flushable writer from an http.ResponseWriter, allowing timely flushing of HTTP responses in tarpit scenarios.
- Introduces the getFlushableWriter helper that unwraps nested response writers.
- Updates the ServeHTTP method to write and flush response chunks using the flushable writer.
- Modifies client disconnect handling and updates go.mod with additional dependencies.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| responders/tarpit/tarpit.go | Added utility function and updated response flushing logic in ServeHTTP. |
| go.mod | Added several indirect dependencies, including xcaddy and others. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jason Cameron <jasoncameron.all@gmail.com>
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
responders/tarpit/tarpit.go
Outdated
| } | ||
|
|
||
| if _, ok := unwrapped.(http.Flusher); ok { | ||
| return unwrapped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Writing to unwrapped writer bypasses response wrappers
When getFlushableWriter returns an unwrapped inner writer (because an outer wrapper doesn't implement http.Flusher), the code writes headers and status to the original w but writes body data to flushableWriter. This inconsistency bypasses any response wrappers in the chain, potentially breaking middleware that transforms data or maintains state. The function conflates finding a Flusher for flushing with finding a writer to write to—writes should always go through the original w, with only the Flush() call using the unwrapped Flusher.
Additional Locations (2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why. I need to fix 2025/05/22 17:04:48.748 DEBUG http.stdlib http: panic serving 192.168.65.1:62029: interface conversion: *caddyhttp.responseRecorder is not http.Flusher: missing method Flush
goroutine 70 [running]:
net/http.(*conn).serve.func1()
Co-authored-by: jasoncameron.all <jasoncameron.all@gmail.com>
|
Cursor Agent can help with this pull request. Just |
|
@cursoragent fix Run golangci/golangci-lint-action@1481404
|
|
Learn more about Cursor Agents |
Co-authored-by: jasoncameron.all <jasoncameron.all@gmail.com>
|
@cursoragent Running [/home/runner/golangci-lint-2.6.2-linux-amd64/golangci-lint config path] in [/home/runner/work/caddy-defender/caddy-defender] ...
|
|
I wrapped the Learn more about Cursor Agents |
Co-authored-by: jasoncameron.all <jasoncameron.all@gmail.com>
Adds a utility function to retrieve a flushable writer from the http.ResponseWriter. This allows flushing the response after writing each chunk of data, ensuring timely delivery to the client, especially in tarpit scenarios.
Closes #84
Note
Unwraps ResponseWriter to obtain a flusher and flushes each streamed chunk in the tarpit responder, with improved disconnect handling and minor tooling/deps updates.
getFlushableWriterto unwraphttp.ResponseWriterand find anhttp.Flusher.ServeHTTPto write the initial buffer and subsequent chunks, flushing after each write; logs a warning if flushing isn’t possible.tool github.com/caddyserver/xcaddy/cmd/xcaddyand related indirect dependencies ingo.mod/go.sum.Written by Cursor Bugbot for commit d1871bb. This will update automatically on new commits. Configure here.