access to remote IPv4 or IPv6 address?

35 views
Skip to first unread message

David Birdsong

unread,
Apr 14, 2015, 2:30:23 PM4/14/15
to gopro...@googlegroups.com
I'm implementing access logs that would be much better if I could log the remote IPv4 or IPv6 addresses that Transport ends up resolving and connecting to (or re-using.)

I'm already providing my own ```Tr``` to the proxy so I can keep a running counter on new connections created with the purpose of deriving a metric around connection re-use:

...but I haven't figured out how to associate a request to a net.Conn.

Does anybody have any suggestions on how to tie a request to a net.Conn?

Elazar Leibovich

unread,
Apr 14, 2015, 2:48:10 PM4/14/15
to David Birdsong, gopro...@googlegroups.com
You can put a specific roundtripper in the context. This roundtripper would tell you which connection to use.

Something like:

proxy.OnRequest().DoFunc(func(req *http.Request, ctx *goproxy.Context) (*http.Request, *http.Response) {
    ctx.RoundTripper = createRoundTripper()
    return req, nil
}

--
You received this message because you are subscribed to the Google Groups "goproxy-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goproxy-dev...@googlegroups.com.
To post to this group, send email to gopro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/goproxy-dev/660c3f15-e8e4-4f02-af86-1220ef5fe973%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Birdsong

unread,
Apr 14, 2015, 2:58:01 PM4/14/15
to Elazar Leibovich, gopro...@googlegroups.com
Of course!

I was looking right at it and not seeing that it was possible to override on a per-request/per-context basis. This makes it possible right? https://github.com/elazarl/goproxy/blob/master/ctx.go#L37

Elazar Leibovich

unread,
Apr 14, 2015, 2:58:48 PM4/14/15
to David Birdsong, gopro...@googlegroups.com
Exactly. That's was the reason for adding this field in Context.

David Birdsong

unread,
Apr 14, 2015, 3:21:26 PM4/14/15
to Elazar Leibovich, gopro...@googlegroups.com
Hmm, so there's still a big challenge here.

I'll continue to want to use a single instance of *http.Transport to leverage it's connection tracking and reuse functionality. I'm thinking I'll need a per-request closure to share data w/ my implementation of Dialer, but to make use of the single *http.Transport on the proxy instance, I'd need to reassign it's Dial member to my Dialer implementation which would be very thread-unsafe.

Patrick Mézard

unread,
Apr 15, 2015, 2:47:32 AM4/15/15
to David Birdsong, Elazar Leibovich, gopro...@googlegroups.com
On 14/04/15 20:57, David Birdsong wrote:
> Of course!
>
> I was looking right at it and not seeing that it was possible to
> override on a per-request/per-context basis. This makes it possible
> right? https://github.com/elazarl/goproxy/blob/master/ctx.go#L37

FWIW, the httpdumper example demonstrates how to do that:

https://github.com/elazarl/goproxy/blob/master/examples/goproxy-httpdump/httpdump.go#L254

--
Patrick Mézard

David Birdsong

unread,
Apr 15, 2015, 10:45:08 PM4/15/15
to gopro...@googlegroups.com, david.b...@gmail.com, ela...@gmail.com
great, this helps!
 

--
Patrick Mézard
Reply all
Reply to author
Forward
0 new messages