-
Notifications
You must be signed in to change notification settings - Fork 3
feat(http): implement Hijack method in ResponseRecorder and enhance e… #32
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,15 @@ | ||||||
| package http | ||||||
|
|
||||||
| import "net/http" | ||||||
| import ( | ||||||
| "bufio" | ||||||
| "net" | ||||||
| "net/http" | ||||||
| ) | ||||||
|
|
||||||
| var _ http.Hijacker = (*ResponseRecorder)(nil) | ||||||
|
|
||||||
| type ResponseRecorder struct { | ||||||
| http.Hijacker | ||||||
| http.ResponseWriter | ||||||
|
|
||||||
| status int | ||||||
|
|
@@ -34,6 +41,14 @@ func (r *ResponseRecorder) WriteHeader(s int) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Hijack implements http.Hijacker. | ||||||
| func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { | ||||||
| if hj, ok := r.ResponseWriter.(http.Hijacker); ok { | ||||||
| return hj.Hijack() | ||||||
| } | ||||||
| return nil, nil, http.ErrHijacked | ||||||
|
||||||
| return nil, nil, http.ErrHijacked | |
| return nil, nil, http.ErrNotSupported |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -275,17 +275,26 @@ func (s *HTTPServer) buildHandler(tripper http.RoundTripper) http.HandlerFunc { | |||||
| }() | ||||||
|
|
||||||
| want := resp.Header.Get("Content-Length") | ||||||
| hasChunked := slices.Contains(resp.TransferEncoding, "chunked") | ||||||
|
|
||||||
| sent, err := io.CopyBuffer(w, resp.Body, *buf) | ||||||
|
|
||||||
| // handle copy error | ||||||
| if err != nil && !errors.Is(err, io.EOF) { | ||||||
| // abort ? continue ? | ||||||
| // quickabort ? continue ? | ||||||
|
||||||
| // quickabort ? continue ? | |
| // quick abort ? continue ? |
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.
Embedding
http.Hijackeras an interface field is unnecessary since theHijackmethod is explicitly implemented below. This embedded field serves no purpose and should be removed to avoid confusion.