Skip to content

Commit

Permalink
Print response client and server address
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxueyao committed Jun 22, 2018
1 parent 635e442 commit 3a3dca9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
netgraph
test.pcap
.vscode/
.idea/
debug
.DS_Store
4 changes: 2 additions & 2 deletions ng.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ func (p *EventPrinter) printHTTPRequestEvent(req ngnet.HTTPRequestEvent) {
}

func (p *EventPrinter) printHTTPResponseEvent(resp ngnet.HTTPResponseEvent) {
fmt.Fprintf(p.file, "[%s] #%d Response \r\n",
resp.Start.Format("2006-01-02 15:04:05.000"), resp.StreamSeq)
fmt.Fprintf(p.file, "[%s] #%d Response %s<-%s\r\n",
resp.Start.Format("2006-01-02 15:04:05.000"), resp.StreamSeq, resp.ClientAddr, resp.ServerAddr)
fmt.Fprintf(p.file, "%s %d %s\r\n", resp.Version, resp.Code, resp.Reason)
for _, h := range resp.Headers {
fmt.Fprintf(p.file, "%s: %s\r\n", h.Name, h.Value)
Expand Down
14 changes: 9 additions & 5 deletions ngnet/httpstreampair.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ type HTTPRequestEvent struct {
// HTTPResponseEvent is HTTP response
type HTTPResponseEvent struct {
HTTPEvent
Version string
Code uint
Reason string
Headers []HTTPHeaderItem
Body []byte
ClientAddr string
ServerAddr string
Version string
Code uint
Reason string
Headers []HTTPHeaderItem
Body []byte
}

// httpStreamPair is Bi-direction HTTP stream pair
Expand Down Expand Up @@ -105,6 +107,8 @@ func (pair *httpStreamPair) handleTransaction() {
respBody := downStream.getBody(method, respHeaders, false)

var resp HTTPResponseEvent
resp.ClientAddr = pair.upStream.key.net.Src().String() + ":" + pair.upStream.key.tcp.Src().String()
resp.ServerAddr = pair.upStream.key.net.Dst().String() + ":" + pair.upStream.key.tcp.Dst().String()
resp.Type = "HTTPResponse"
resp.Version = respVersion
resp.Code = uint(code)
Expand Down

0 comments on commit 3a3dca9

Please sign in to comment.