Rebase.
[official-gcc.git] / libgo / go / net / http / export_test.go
blob960563b240945d9547cb4d4c6e87d9a09708b6ff
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.
5 // Bridge package to expose http internals to tests in the http_test
6 // package.
8 package http
10 import (
11 "net"
12 "time"
15 func NewLoggingConn(baseName string, c net.Conn) net.Conn {
16 return newLoggingConn(baseName, c)
19 var ExportAppendTime = appendTime
21 func (t *Transport) NumPendingRequestsForTesting() int {
22 t.reqMu.Lock()
23 defer t.reqMu.Unlock()
24 return len(t.reqCanceler)
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
34 for key := range t.idleConn {
35 keys = append(keys, key.String())
37 return
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
46 for k, conns := range t.idleConn {
47 if k.String() == cacheKey {
48 return len(conns)
51 return 0
54 func (t *Transport) IdleConnChMapSizeForTesting() int {
55 t.idleMu.Lock()
56 defer t.idleMu.Unlock()
57 return len(t.idleConnCh)
60 func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler {
61 f := func() <-chan time.Time {
62 return ch
64 return &timeoutHandler{handler, f, ""}
67 func ResetCachedEnvironment() {
68 httpProxyEnv.reset()
69 noProxyEnv.reset()
72 var DefaultUserAgent = defaultUserAgent