Skip to content
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

Hijacker interface added #105

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions response_writer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gin

import (
"bufio"
"errors"
"log"
"net"
"net/http"
)

Expand All @@ -11,6 +14,7 @@ type (
Status() int
Written() bool
WriteHeaderNow()
Hijack() (net.Conn, *bufio.ReadWriter, error)
}

responseWriter struct {
Expand Down Expand Up @@ -54,3 +58,12 @@ func (w *responseWriter) Status() int {
func (w *responseWriter) Written() bool {
return w.written
}

// allow connection hijacking
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
hijacker, ok := w.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface")
}
return hijacker.Hijack()
}