Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
#25 Implement http.Hijack interface to make https://github.com/caddys…
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Jan 21, 2018
1 parent ad1c8e2 commit 70ca06d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions responseWriterWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"io/ioutil"
"net/http"
"strings"
"net"
"bufio"
"github.com/mholt/caddy/caddyhttp/httpserver"
)

func newResponseWriterWrapperFor(delegate http.ResponseWriter, beforeFirstWrite func(*responseWriterWrapper) bool) *responseWriterWrapper {
Expand Down Expand Up @@ -174,6 +177,15 @@ func (instance *responseWriterWrapper) recorded() []byte {
return buffer.Bytes()
}

// Hijack implements http.Hijacker. It simply wraps the underlying
// ResponseWriter's Hijack method if there is one, or returns an error.
func (instance *responseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hj, ok := instance.delegate.(http.Hijacker); ok {
return hj.Hijack()
}
return nil, nil, httpserver.NonHijackerError{Underlying: instance.delegate}
}

func (instance *responseWriterWrapper) recordedAndDecodeIfRequired() []byte {
result := instance.recorded()
if !instance.isGzipEncoded() {
Expand Down

0 comments on commit 70ca06d

Please sign in to comment.