X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/net/http
opt
/
golang
/
1.22.0
/
src
/
net
/
http
/
📁
..
📄
alpn_test.go
(3.01 KB)
📁
cgi
📄
client.go
(33.4 KB)
📄
client_test.go
(63.24 KB)
📄
clientserver_test.go
(46.07 KB)
📄
clone.go
(1.56 KB)
📄
cookie.go
(11.53 KB)
📄
cookie_test.go
(19.26 KB)
📁
cookiejar
📄
doc.go
(3.42 KB)
📄
example_filesystem_test.go
(2.04 KB)
📄
example_handle_test.go
(560 B)
📄
example_test.go
(5.38 KB)
📄
export_test.go
(8.43 KB)
📁
fcgi
📄
filetransport.go
(3.52 KB)
📄
filetransport_test.go
(2.62 KB)
📄
fs.go
(30.36 KB)
📄
fs_test.go
(46.7 KB)
📄
h2_bundle.go
(357.28 KB)
📄
h2_error.go
(812 B)
📄
h2_error_test.go
(1.04 KB)
📄
header.go
(7.9 KB)
📄
header_test.go
(6.05 KB)
📄
http.go
(5.13 KB)
📄
http_test.go
(5.22 KB)
📁
httptest
📁
httptrace
📁
httputil
📁
internal
📄
jar.go
(900 B)
📄
main_test.go
(4.94 KB)
📄
mapping.go
(1.68 KB)
📄
mapping_test.go
(2.95 KB)
📄
method.go
(517 B)
📄
omithttp2.go
(1.91 KB)
📄
pattern.go
(15.17 KB)
📄
pattern_test.go
(14.5 KB)
📁
pprof
📄
proxy_test.go
(1.16 KB)
📄
range_test.go
(2.38 KB)
📄
readrequest_test.go
(9.7 KB)
📄
request.go
(48.34 KB)
📄
request_test.go
(42.39 KB)
📄
requestwrite_test.go
(23.3 KB)
📄
response.go
(11.1 KB)
📄
response_test.go
(23.63 KB)
📄
responsecontroller.go
(4.17 KB)
📄
responsecontroller_test.go
(9.81 KB)
📄
responsewrite_test.go
(6.89 KB)
📄
roundtrip.go
(566 B)
📄
roundtrip_js.go
(11.8 KB)
📄
routing_index.go
(3.95 KB)
📄
routing_index_test.go
(4.02 KB)
📄
routing_tree.go
(7.48 KB)
📄
routing_tree_test.go
(6.89 KB)
📄
serve_test.go
(192.54 KB)
📄
servemux121.go
(5.6 KB)
📄
server.go
(120.67 KB)
📄
server_test.go
(6.95 KB)
📄
sniff.go
(7.9 KB)
📄
sniff_test.go
(9.56 KB)
📄
socks_bundle.go
(12.9 KB)
📄
status.go
(7.45 KB)
📁
testdata
📄
transfer.go
(30.89 KB)
📄
transfer_test.go
(9.13 KB)
📄
transport.go
(87.81 KB)
📄
transport_default_other.go
(362 B)
📄
transport_default_wasm.go
(364 B)
📄
transport_internal_test.go
(6.05 KB)
📄
transport_test.go
(186.06 KB)
📄
triv.go
(3.22 KB)
Editing: main_test.go
// Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package http_test import ( "fmt" "io" "log" "net/http" "os" "runtime" "sort" "strings" "testing" "time" ) var quietLog = log.New(io.Discard, "", 0) func TestMain(m *testing.M) { *http.MaxWriteWaitBeforeConnReuse = 60 * time.Minute v := m.Run() if v == 0 && goroutineLeaked() { os.Exit(1) } os.Exit(v) } func interestingGoroutines() (gs []string) { buf := make([]byte, 2<<20) buf = buf[:runtime.Stack(buf, true)] for _, g := range strings.Split(string(buf), "\n\n") { _, stack, _ := strings.Cut(g, "\n") stack = strings.TrimSpace(stack) if stack == "" || strings.Contains(stack, "testing.(*M).before.func1") || strings.Contains(stack, "os/signal.signal_recv") || strings.Contains(stack, "created by net.startServer") || strings.Contains(stack, "created by testing.RunTests") || strings.Contains(stack, "closeWriteAndWait") || strings.Contains(stack, "testing.Main(") || // These only show up with GOTRACEBACK=2; Issue 5005 (comment 28) strings.Contains(stack, "runtime.goexit") || strings.Contains(stack, "created by runtime.gc") || strings.Contains(stack, "interestingGoroutines") || strings.Contains(stack, "runtime.MHeap_Scavenger") { continue } gs = append(gs, stack) } sort.Strings(gs) return } // Verify the other tests didn't leave any goroutines running. func goroutineLeaked() bool { if testing.Short() || runningBenchmarks() { // Don't worry about goroutine leaks in -short mode or in // benchmark mode. Too distracting when there are false positives. return false } var stackCount map[string]int for i := 0; i < 5; i++ { n := 0 stackCount = make(map[string]int) gs := interestingGoroutines() for _, g := range gs { stackCount[g]++ n++ } if n == 0 { return false } // Wait for goroutines to schedule and die off: time.Sleep(100 * time.Millisecond) } fmt.Fprintf(os.Stderr, "Too many goroutines running after net/http test(s).\n") for stack, count := range stackCount { fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack) } return true } // setParallel marks t as a parallel test if we're in short mode // (all.bash), but as a serial test otherwise. Using t.Parallel isn't // compatible with the afterTest func in non-short mode. func setParallel(t *testing.T) { if strings.Contains(t.Name(), "HTTP2") { http.CondSkipHTTP2(t) } if testing.Short() { t.Parallel() } } func runningBenchmarks() bool { for i, arg := range os.Args { if strings.HasPrefix(arg, "-test.bench=") && !strings.HasSuffix(arg, "=") { return true } if arg == "-test.bench" && i < len(os.Args)-1 && os.Args[i+1] != "" { return true } } return false } var leakReported bool func afterTest(t testing.TB) { http.DefaultTransport.(*http.Transport).CloseIdleConnections() if testing.Short() { return } if leakReported { // To avoid confusion, only report the first leak of each test run. // After the first leak has been reported, we can't tell whether the leaked // goroutines are a new leak from a subsequent test or just the same // goroutines from the first leak still hanging around, and we may add a lot // of latency waiting for them to exit at the end of each test. return } // We shouldn't be running the leak check for parallel tests, because we might // report the goroutines from a test that is still running as a leak from a // completely separate test that has just finished. So we use non-atomic loads // and stores for the leakReported variable, and store every time we start a // leak check so that the race detector will flag concurrent leak checks as a // race even if we don't detect any leaks. leakReported = true var bad string badSubstring := map[string]string{ ").readLoop(": "a Transport", ").writeLoop(": "a Transport", "created by net/http/httptest.(*Server).Start": "an httptest.Server", "timeoutHandler": "a TimeoutHandler", "net.(*netFD).connect(": "a timing out dial", ").noteClientGone(": "a closenotifier sender", } var stacks string for i := 0; i < 10; i++ { bad = "" stacks = strings.Join(interestingGoroutines(), "\n\n") for substr, what := range badSubstring { if strings.Contains(stacks, substr) { bad = what } } if bad == "" { leakReported = false return } // Bad stuff found, but goroutines might just still be // shutting down, so give it some time. time.Sleep(250 * time.Millisecond) } t.Errorf("Test appears to have leaked %s:\n%s", bad, stacks) } // waitCondition waits for fn to return true, // checking immediately and then at exponentially increasing intervals. func waitCondition(t testing.TB, delay time.Duration, fn func(time.Duration) bool) { t.Helper() start := time.Now() var since time.Duration for !fn(since) { time.Sleep(delay) delay = 2*delay - (delay / 2) // 1.5x, rounded up since = time.Since(start) } }
Upload File
Create Folder