aboutsummaryrefslogtreecommitdiff
path: root/src/vendor/golang.org/x/net/quic/errors.go
diff options
context:
space:
mode:
authorNicholas S. Husin <nsh@golang.org>2026-03-30 19:17:03 -0400
committerNicholas Husin <nsh@golang.org>2026-04-10 08:24:28 -0700
commit2f3c778b232dd53c41e1b623d25cd9f4ab28aaa5 (patch)
tree3959d70ffde2c7c385b0cc5c62cb3ac56dbe1516 /src/vendor/golang.org/x/net/quic/errors.go
parentce4459cf0ee339b3bcf0ed10427079a234aade36 (diff)
downloadgo-2f3c778b232dd53c41e1b623d25cd9f4ab28aaa5.tar.xz
net/http: add support for running HTTP tests against HTTP/3
Add support within clientserver_test.go to bring up a test HTTP/3 server and client when http3Mode testMode option is passed. To be able to reuse net/http/httptest, net/http/httptest.Server.StartTLS (and Start) have been modified so they can be called with a nil Listener. In such cases, both methods will behave identically as usual, but will not actually make its server serve or set its transport dialer, both of which requires having a listener. This should be a no-op for regular users of the package, whose entrypoint via functions such as NewServer will automatically set a local listener. Actually enabling HTTP/3 for our tests will be done in a separate CL. For #70914 Change-Id: Ibc5fc83287b6a04b46e668a54924761a92b620a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/740122 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/vendor/golang.org/x/net/quic/errors.go')
-rw-r--r--src/vendor/golang.org/x/net/quic/errors.go129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/vendor/golang.org/x/net/quic/errors.go b/src/vendor/golang.org/x/net/quic/errors.go
new file mode 100644
index 0000000000..1226370d26
--- /dev/null
+++ b/src/vendor/golang.org/x/net/quic/errors.go
@@ -0,0 +1,129 @@
+// Copyright 2023 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 quic
+
+import (
+ "fmt"
+)
+
+// A transportError is a transport error code from RFC 9000 Section 20.1.
+//
+// The transportError type doesn't implement the error interface to ensure we always
+// distinguish between errors sent to and received from the peer.
+// See the localTransportError and peerTransportError types below.
+type transportError uint64
+
+// https://www.rfc-editor.org/rfc/rfc9000.html#section-20.1
+const (
+ errNo = transportError(0x00)
+ errInternal = transportError(0x01)
+ errConnectionRefused = transportError(0x02)
+ errFlowControl = transportError(0x03)
+ errStreamLimit = transportError(0x04)
+ errStreamState = transportError(0x05)
+ errFinalSize = transportError(0x06)
+ errFrameEncoding = transportError(0x07)
+ errTransportParameter = transportError(0x08)
+ errConnectionIDLimit = transportError(0x09)
+ errProtocolViolation = transportError(0x0a)
+ errInvalidToken = transportError(0x0b)
+ errApplicationError = transportError(0x0c)
+ errCryptoBufferExceeded = transportError(0x0d)
+ errKeyUpdateError = transportError(0x0e)
+ errAEADLimitReached = transportError(0x0f)
+ errNoViablePath = transportError(0x10)
+ errTLSBase = transportError(0x0100) // 0x0100-0x01ff; base + TLS code
+)
+
+func (e transportError) String() string {
+ switch e {
+ case errNo:
+ return "NO_ERROR"
+ case errInternal:
+ return "INTERNAL_ERROR"
+ case errConnectionRefused:
+ return "CONNECTION_REFUSED"
+ case errFlowControl:
+ return "FLOW_CONTROL_ERROR"
+ case errStreamLimit:
+ return "STREAM_LIMIT_ERROR"
+ case errStreamState:
+ return "STREAM_STATE_ERROR"
+ case errFinalSize:
+ return "FINAL_SIZE_ERROR"
+ case errFrameEncoding:
+ return "FRAME_ENCODING_ERROR"
+ case errTransportParameter:
+ return "TRANSPORT_PARAMETER_ERROR"
+ case errConnectionIDLimit:
+ return "CONNECTION_ID_LIMIT_ERROR"
+ case errProtocolViolation:
+ return "PROTOCOL_VIOLATION"
+ case errInvalidToken:
+ return "INVALID_TOKEN"
+ case errApplicationError:
+ return "APPLICATION_ERROR"
+ case errCryptoBufferExceeded:
+ return "CRYPTO_BUFFER_EXCEEDED"
+ case errKeyUpdateError:
+ return "KEY_UPDATE_ERROR"
+ case errAEADLimitReached:
+ return "AEAD_LIMIT_REACHED"
+ case errNoViablePath:
+ return "NO_VIABLE_PATH"
+ }
+ if e >= 0x0100 && e <= 0x01ff {
+ return fmt.Sprintf("CRYPTO_ERROR(%v)", uint64(e)&0xff)
+ }
+ return fmt.Sprintf("ERROR %d", uint64(e))
+}
+
+// A localTransportError is an error sent to the peer.
+type localTransportError struct {
+ code transportError
+ reason string
+}
+
+func (e localTransportError) Error() string {
+ if e.reason == "" {
+ return fmt.Sprintf("closed connection: %v", e.code)
+ }
+ return fmt.Sprintf("closed connection: %v: %q", e.code, e.reason)
+}
+
+// A peerTransportError is an error received from the peer.
+type peerTransportError struct {
+ code transportError
+ reason string
+}
+
+func (e peerTransportError) Error() string {
+ return fmt.Sprintf("peer closed connection: %v: %q", e.code, e.reason)
+}
+
+// A StreamErrorCode is an application protocol error code (RFC 9000, Section 20.2)
+// indicating why a stream is being closed.
+type StreamErrorCode uint64
+
+func (e StreamErrorCode) Error() string {
+ return fmt.Sprintf("stream error code %v", uint64(e))
+}
+
+// An ApplicationError is an application protocol error code (RFC 9000, Section 20.2).
+// Application protocol errors may be sent when terminating a stream or connection.
+type ApplicationError struct {
+ Code uint64
+ Reason string
+}
+
+func (e *ApplicationError) Error() string {
+ return fmt.Sprintf("peer closed connection: %v: %q", e.Code, e.Reason)
+}
+
+// Is reports a match if err is an *ApplicationError with a matching Code.
+func (e *ApplicationError) Is(err error) bool {
+ e2, ok := err.(*ApplicationError)
+ return ok && e2.Code == e.Code
+}