Skip to content

Commit 78717f9

Browse files
neildgopherbot
authored andcommitted
internal/http3: error codes
Define constants for RFC 9114 and RFC 9204 error codes. For golang/go#70914 Change-Id: Icddaf0ef1468adc6ac8e7b8739d45c8e4400f0e4 Reviewed-on: https://go-review.googlesource.com/c/net/+/641837 Auto-Submit: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 84b528b commit 78717f9

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

internal/http3/errors.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2025 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+
//go:build go1.24
6+
7+
package http3
8+
9+
import "fmt"
10+
11+
// http3Error is an HTTP/3 error code.
12+
type http3Error int
13+
14+
const (
15+
// https://www.rfc-editor.org/rfc/rfc9114.html#section-8.1
16+
errH3NoError = http3Error(0x0100)
17+
errH3GeneralProtocolError = http3Error(0x0101)
18+
errH3InternalError = http3Error(0x0102)
19+
errH3StreamCreationError = http3Error(0x0103)
20+
errH3ClosedCriticalStream = http3Error(0x0104)
21+
errH3FrameUnexpected = http3Error(0x0105)
22+
errH3FrameError = http3Error(0x0106)
23+
errH3ExcessiveLoad = http3Error(0x0107)
24+
errH3IDError = http3Error(0x0108)
25+
errH3SettingsError = http3Error(0x0109)
26+
errH3MissingSettings = http3Error(0x010a)
27+
errH3RequestRejected = http3Error(0x010b)
28+
errH3RequestCancelled = http3Error(0x010c)
29+
errH3RequestIncomplete = http3Error(0x010d)
30+
errH3MessageError = http3Error(0x010e)
31+
errH3ConnectError = http3Error(0x010f)
32+
errH3VersionFallback = http3Error(0x0110)
33+
34+
// https://www.rfc-editor.org/rfc/rfc9204.html#section-8.3
35+
errQPACKDecompressionFailed = http3Error(0x0200)
36+
errQPACKEncoderStreamError = http3Error(0x0201)
37+
errQPACKDecoderStreamError = http3Error(0x0202)
38+
)
39+
40+
func (e http3Error) Error() string {
41+
switch e {
42+
case errH3NoError:
43+
return "H3_NO_ERROR"
44+
case errH3GeneralProtocolError:
45+
return "H3_GENERAL_PROTOCOL_ERROR"
46+
case errH3InternalError:
47+
return "H3_INTERNAL_ERROR"
48+
case errH3StreamCreationError:
49+
return "H3_STREAM_CREATION_ERROR"
50+
case errH3ClosedCriticalStream:
51+
return "H3_CLOSED_CRITICAL_STREAM"
52+
case errH3FrameUnexpected:
53+
return "H3_FRAME_UNEXPECTED"
54+
case errH3FrameError:
55+
return "H3_FRAME_ERROR"
56+
case errH3ExcessiveLoad:
57+
return "H3_EXCESSIVE_LOAD"
58+
case errH3IDError:
59+
return "H3_ID_ERROR"
60+
case errH3SettingsError:
61+
return "H3_SETTINGS_ERROR"
62+
case errH3MissingSettings:
63+
return "H3_MISSING_SETTINGS"
64+
case errH3RequestRejected:
65+
return "H3_REQUEST_REJECTED"
66+
case errH3RequestCancelled:
67+
return "H3_REQUEST_CANCELLED"
68+
case errH3RequestIncomplete:
69+
return "H3_REQUEST_INCOMPLETE"
70+
case errH3MessageError:
71+
return "H3_MESSAGE_ERROR"
72+
case errH3ConnectError:
73+
return "H3_CONNECT_ERROR"
74+
case errH3VersionFallback:
75+
return "H3_VERSION_FALLBACK"
76+
case errQPACKDecompressionFailed:
77+
return "QPACK_DECOMPRESSION_FAILED"
78+
case errQPACKEncoderStreamError:
79+
return "QPACK_ENCODER_STREAM_ERROR"
80+
case errQPACKDecoderStreamError:
81+
return "QPACK_DECODER_STREAM_ERROR"
82+
}
83+
return fmt.Sprintf("H3_ERROR_%v", int(e))
84+
}

0 commit comments

Comments
 (0)