github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/net/http/export_test.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Bridge package to expose http internals to tests in the http_test 6 // package. 7 8 package http 9 10 import ( 11 "net" 12 "time" 13 ) 14 15 func NewLoggingConn(baseName string, c net.Conn) net.Conn { 16 return newLoggingConn(baseName, c) 17 } 18 19 var ExportAppendTime = appendTime 20 21 func (t *Transport) NumPendingRequestsForTesting() int { 22 t.reqMu.Lock() 23 defer t.reqMu.Unlock() 24 return len(t.reqCanceler) 25 } 26 27 func (t *Transport) IdleConnKeysForTesting() (keys []string) { 28 keys = make([]string, 0) 29 t.idleMu.Lock() 30 defer t.idleMu.Unlock() 31 if t.idleConn == nil { 32 return 33 } 34 for key := range t.idleConn { 35 keys = append(keys, key.String()) 36 } 37 return 38 } 39 40 func (t *Transport) IdleConnCountForTesting(cacheKey string) int { 41 t.idleMu.Lock() 42 defer t.idleMu.Unlock() 43 if t.idleConn == nil { 44 return 0 45 } 46 for k, conns := range t.idleConn { 47 if k.String() == cacheKey { 48 return len(conns) 49 } 50 } 51 return 0 52 } 53 54 func (t *Transport) IdleConnChMapSizeForTesting() int { 55 t.idleMu.Lock() 56 defer t.idleMu.Unlock() 57 return len(t.idleConnCh) 58 } 59 60 func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler { 61 f := func() <-chan time.Time { 62 return ch 63 } 64 return &timeoutHandler{handler, f, ""} 65 } 66 67 func ResetCachedEnvironment() { 68 httpProxyEnv.reset() 69 noProxyEnv.reset() 70 } 71 72 var DefaultUserAgent = defaultUserAgent