Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/net
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.33.0
Choose a base ref
...
head repository: golang/net
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.38.0
Choose a head ref
Loading
Showing with 11,271 additions and 4,524 deletions.
  1. +100 −12 context/context.go
  2. +0 −583 context/context_test.go
  3. +1 −1 context/ctxhttp/ctxhttp.go
  4. +0 −72 context/go17.go
  5. +0 −20 context/go19.go
  6. +0 −300 context/pre_go17.go
  7. +0 −109 context/pre_go19.go
  8. +0 −31 context/withtimeout_test.go
  9. +5 −5 go.mod
  10. +8 −8 go.sum
  11. +1 −0 html/atom/gen.go
  12. +629 −627 html/atom/table.go
  13. +1 −0 html/atom/table_test.go
  14. +2 −2 html/parse.go
  15. +17 −0 html/parse_test.go
  16. +16 −2 html/token.go
  17. +18 −0 html/token_test.go
  18. +8 −2 http/httpproxy/proxy.go
  19. +7 −0 http/httpproxy/proxy_test.go
  20. +8 −7 http2/clientconn_test.go
  21. +1 −1 http2/config.go
  22. +1 −1 http2/config_go124.go
  23. +11 −0 http2/frame.go
  24. +4 −10 http2/h2c/h2c.go
  25. +15 −24 http2/http2.go
  26. +9 −0 http2/http2_test.go
  27. +1 −1 http2/netconn_test.go
  28. +44 −86 http2/server.go
  29. +23 −1 http2/server_test.go
  30. +45 −9 http2/sync_test.go
  31. +47 −300 http2/transport.go
  32. +119 −26 http2/transport_test.go
  33. +2 −1 http2/write.go
  34. +19 −28 http2/gate_test.go → internal/gate/gate.go
  35. +85 −0 internal/gate/gate_test.go
  36. +142 −0 internal/http3/body.go
  37. +276 −0 internal/http3/body_test.go
  38. +133 −0 internal/http3/conn.go
  39. +154 −0 internal/http3/conn_test.go
  40. +10 −0 internal/http3/doc.go
  41. +104 −0 internal/http3/errors.go
  42. +56 −0 internal/http3/files_test.go
  43. +86 −0 internal/http3/http3.go
  44. +48 −0 internal/http3/http3_synctest_test.go
  45. +44 −0 internal/http3/http3_test.go
  46. +334 −0 internal/http3/qpack.go
  47. +83 −0 internal/http3/qpack_decode.go
  48. +196 −0 internal/http3/qpack_decode_test.go
  49. +47 −0 internal/http3/qpack_encode.go
  50. +126 −0 internal/http3/qpack_encode_test.go
  51. +144 −0 internal/http3/qpack_static.go
  52. +173 −0 internal/http3/qpack_test.go
  53. +42 −0 internal/http3/quic.go
  54. +234 −0 internal/http3/quic_test.go
  55. +347 −0 internal/http3/roundtrip.go
  56. +354 −0 internal/http3/roundtrip_test.go
  57. +172 −0 internal/http3/server.go
  58. +110 −0 internal/http3/server_test.go
  59. +72 −0 internal/http3/settings.go
  60. +262 −0 internal/http3/stream.go
  61. +319 −0 internal/http3/stream_test.go
  62. +190 −0 internal/http3/transport.go
  63. +448 −0 internal/http3/transport_test.go
  64. +53 −0 internal/httpcommon/ascii.go
  65. +17 −7 {http2 → internal/httpcommon}/headermap.go
  66. +37 −0 internal/httpcommon/httpcommon_test.go
  67. +467 −0 internal/httpcommon/request.go
  68. +672 −0 internal/httpcommon/request_test.go
  69. +28 −26 {quic → internal/quic/quicwire}/wire.go
  70. +35 −35 {quic → internal/quic/quicwire}/wire_test.go
  71. +1 −5 internal/socket/socket_test.go
  72. +36 −0 internal/testcert/testcert.go
  73. +5 −3 proxy/per_host.go
  74. +111 −47 proxy/per_host_test.go
  75. BIN publicsuffix/data/children
  76. BIN publicsuffix/data/nodes
  77. +1 −1 publicsuffix/data/text
  78. +0 −2 publicsuffix/example_test.go
  79. +14 −58 publicsuffix/gen.go
  80. +15 −13 publicsuffix/list.go
  81. +9 −25 publicsuffix/list_test.go
  82. +6 −6 publicsuffix/table.go
  83. +3,090 −1,670 publicsuffix/table_test.go
  84. +5 −3 quic/config.go
  85. +5 −0 quic/conn.go
  86. +12 −1 quic/conn_close.go
  87. +62 −67 quic/conn_id.go
  88. +49 −0 quic/conn_id_test.go
  89. +1 −1 quic/conn_test.go
  90. +20 −1 quic/endpoint.go
  91. +1 −2 quic/errors.go
  92. +2 −2 quic/gate.go
  93. +9 −7 quic/packet.go
  94. +2 −1 quic/packet_codec_test.go
  95. +45 −43 quic/packet_parser.go
  96. +1 −1 quic/packet_protection.go
  97. +62 −60 quic/packet_writer.go
  98. +2 −2 quic/qlog/json_writer.go
  99. +8 −0 quic/rangeset.go
  100. +8 −7 quic/retry.go
  101. +1 −1 quic/rtt.go
  102. +6 −4 quic/sent_packet.go
  103. +1 −1 quic/sent_val.go
  104. +42 −12 quic/stream.go
  105. +80 −4 quic/stream_test.go
  106. +3 −28 quic/tlsconfig_test.go
  107. +60 −58 quic/transport_params.go
  108. +5 −3 quic/transport_params_test.go
  109. +69 −0 quic/udp_packetconn.go
  110. +50 −36 route/address.go
  111. +35 −3 route/address_darwin_test.go
  112. +70 −0 route/example_darwin_test.go
  113. +1 −1 route/sys_netbsd.go
  114. +1 −6 webdav/file_test.go
  115. +3 −2 websocket/websocket.go
112 changes: 100 additions & 12 deletions context/context.go
Original file line number Diff line number Diff line change
@@ -3,29 +3,31 @@
// license that can be found in the LICENSE file.

// Package context defines the Context type, which carries deadlines,
// cancelation signals, and other request-scoped values across API boundaries
// cancellation signals, and other request-scoped values across API boundaries
// and between processes.
// As of Go 1.7 this package is available in the standard library under the
// name context. https://golang.org/pkg/context.
// name [context], and migrating to it can be done automatically with [go fix].
//
// Incoming requests to a server should create a Context, and outgoing calls to
// servers should accept a Context. The chain of function calls between must
// propagate the Context, optionally replacing it with a modified copy created
// using WithDeadline, WithTimeout, WithCancel, or WithValue.
// Incoming requests to a server should create a [Context], and outgoing
// calls to servers should accept a Context. The chain of function
// calls between them must propagate the Context, optionally replacing
// it with a derived Context created using [WithCancel], [WithDeadline],
// [WithTimeout], or [WithValue].
//
// Programs that use Contexts should follow these rules to keep interfaces
// consistent across packages and enable static analysis tools to check context
// propagation:
//
// Do not store Contexts inside a struct type; instead, pass a Context
// explicitly to each function that needs it. The Context should be the first
// explicitly to each function that needs it. This is discussed further in
// https://go.dev/blog/context-and-structs. The Context should be the first
// parameter, typically named ctx:
//
// func DoSomething(ctx context.Context, arg Arg) error {
// // ... use ctx ...
// }
//
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
// Do not pass a nil [Context], even if a function permits it. Pass [context.TODO]
// if you are unsure about which Context to use.
//
// Use context Values only for request-scoped data that transits processes and
@@ -34,9 +36,30 @@
// The same Context may be passed to functions running in different goroutines;
// Contexts are safe for simultaneous use by multiple goroutines.
//
// See http://blog.golang.org/context for example code for a server that uses
// See https://go.dev/blog/context for example code for a server that uses
// Contexts.
package context // import "golang.org/x/net/context"
//
// [go fix]: https://go.dev/cmd/go#hdr-Update_packages_to_use_new_APIs
package context

import (
"context" // standard library's context, as of Go 1.7
"time"
)

// A Context carries a deadline, a cancellation signal, and other values across
// API boundaries.
//
// Context's methods may be called by multiple goroutines simultaneously.
type Context = context.Context

// Canceled is the error returned by [Context.Err] when the context is canceled
// for some reason other than its deadline passing.
var Canceled = context.Canceled

// DeadlineExceeded is the error returned by [Context.Err] when the context is canceled
// due to its deadline passing.
var DeadlineExceeded = context.DeadlineExceeded

// Background returns a non-nil, empty Context. It is never canceled, has no
// values, and has no deadline. It is typically used by the main function,
@@ -49,8 +72,73 @@ func Background() Context {
// TODO returns a non-nil, empty Context. Code should use context.TODO when
// it's unclear which Context to use or it is not yet available (because the
// surrounding function has not yet been extended to accept a Context
// parameter). TODO is recognized by static analysis tools that determine
// whether Contexts are propagated correctly in a program.
// parameter).
func TODO() Context {
return todo
}

var (
background = context.Background()
todo = context.TODO()
)

// A CancelFunc tells an operation to abandon its work.
// A CancelFunc does not wait for the work to stop.
// A CancelFunc may be called by multiple goroutines simultaneously.
// After the first call, subsequent calls to a CancelFunc do nothing.
type CancelFunc = context.CancelFunc

// WithCancel returns a derived context that points to the parent context
// but has a new Done channel. The returned context's Done channel is closed
// when the returned cancel function is called or when the parent context's
// Done channel is closed, whichever happens first.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete.
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
return context.WithCancel(parent)
}

// WithDeadline returns a derived context that points to the parent context
// but has the deadline adjusted to be no later than d. If the parent's
// deadline is already earlier than d, WithDeadline(parent, d) is semantically
// equivalent to parent. The returned [Context.Done] channel is closed when
// the deadline expires, when the returned cancel function is called,
// or when the parent context's Done channel is closed, whichever happens first.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete.
func WithDeadline(parent Context, d time.Time) (Context, CancelFunc) {
return context.WithDeadline(parent, d)
}

// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this [Context] complete:
//
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
// defer cancel() // releases resources if slowOperation completes before timeout elapses
// return slowOperation(ctx)
// }
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
return context.WithTimeout(parent, timeout)
}

// WithValue returns a derived context that points to the parent Context.
// In the derived context, the value associated with key is val.
//
// Use context Values only for request-scoped data that transits processes and
// APIs, not for passing optional parameters to functions.
//
// The provided key must be comparable and should not be of type
// string or any other built-in type to avoid collisions between
// packages using context. Users of WithValue should define their own
// types for keys. To avoid allocating when assigning to an
// interface{}, context keys often have concrete type
// struct{}. Alternatively, exported context key variables' static
// type should be a pointer or interface.
func WithValue(parent Context, key, val interface{}) Context {
return context.WithValue(parent, key, val)
}
Loading