Question

I know http.Client in Go language has connection pool in type Transport

But there is no Transport in http.Server

I wish to access server's pool.

  1. List all connections
  2. Close connections/remove them from pool

Update

I am learning Go source code https://code.google.com/p/go/source/browse/src/pkg/net/http/server.go#1087

It seems that this function has the answer that there is no Pool.

May be someone knows how to override that function? Do I have to create a hole copy of package?

Was it helpful?

Solution

I got answer on go-nuts mailing list.

https://groups.google.com/forum/#!topic/golang-nuts/eoBsx0Sl3Co

  1. Transport is not available in server (only in client)
  2. I can pass my own net.Listener
  3. LimitListener is one of such implementations. https://code.google.com/p/go/source/browse/netutil/listen.go?repo=net

OTHER TIPS

EDIT: Note that the Transport struct corresponds to an http client, not an http server

The Transport struct lives here: https://code.google.com/p/go/source/browse/src/pkg/net/http/transport.go

In that struct there are a few members of interest:

idleConn
idleConnCh
reqConn

I think strictly speaking this is what you are asking about.

However those are not exported and it's pretty clear the author did not intend those to be modified by from other packages.

I would suggest having a look at CloseIdleConnections, CancelRequest - those seem to be the exported functions that deal with the connection pool, maybe that solves part of your problem.

Otherwise, you're basically up against "it wasn't designed to do that". There is apparently (someone might come along and correct me on this, but I haven't see how) no way to extend built-in types in a fashion that lets you access members which are only visible within it's package (i.e. members that start with a lower case letter). Meaning you can't access those members of the Transport struct without modifying the source of the http package (or copying it and making your own).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top