Skip to content

Commit

Permalink
TeeReader
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga committed Sep 22, 2022
1 parent 0cc0c0e commit 37b93b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ftwhttp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftwhttp

import (
"bufio"
"bytes"
"errors"
"io"
"net"
Expand Down Expand Up @@ -104,13 +105,20 @@ func (c *Connection) Response() (*Response, error) {
return nil, err
}

reader := *bufio.NewReader(r)
buf := &bytes.Buffer{}

reader := *bufio.NewReader(io.TeeReader(r, buf))

httpResponse, err := http.ReadResponse(&reader, nil)
if err != nil {
return nil, err
}

data := buf.Bytes()
log.Trace().Msgf("ftw/http: received data - %q", data)

response := Response{
RAW: data,
Parsed: *httpResponse,
}
return &response, err
Expand Down
1 change: 1 addition & 0 deletions ftwhttp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ type Request struct {

// Response represents the http response received from the server/waf
type Response struct {
RAW []byte
Parsed http.Response
}

0 comments on commit 37b93b6

Please sign in to comment.