-
Notifications
You must be signed in to change notification settings - Fork 4.6k
transport/grpcframer: create grpcframer package #7397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
be858f0
create grpcframer package
printchard a77e5d5
change file location to new package name
printchard 070d347
address comments
printchard 78c4957
add meta decoder to interface
printchard cb35582
add SetMetaDecoder to interface
printchard 4a02377
add MetaHeadersFrame and change struct fields to pointers.
printchard 10207e3
address comments
printchard 5990250
change flags to flag
printchard 67e36ff
make settings an exported field
printchard 610bf63
add documentation to frames
printchard 4c20283
add test and more documentation to frame types
printchard 6a18aed
add missing copyright notice
printchard cc8bc6b
change test to include all values
printchard 93fc866
move test to same package
printchard e450516
change tests to comply with style guide
printchard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package grpchttp2 | ||
|
|
||
| import "fmt" | ||
|
|
||
| // ErrCode represents an HTTP/2 Error Code. Error codes are 32-bit fields | ||
| // that are used in [RST_STREAM] and [GOAWAY] frames to convey the reasons for | ||
| // the stream or connection error. See [HTTP/2 Error Code] for definitions of | ||
| // each of the following error codes. | ||
| // | ||
| // [HTTP/2 Error Code]: https://httpwg.org/specs/rfc7540.html#ErrorCodes | ||
| // [RST_STREAM]: https://httpwg.org/specs/rfc7540.html#RST_STREAM | ||
| // [GOAWAY]: https://httpwg.org/specs/rfc7540.html#GOAWAY | ||
| type ErrCode uint32 | ||
|
|
||
| const ( | ||
| ErrCodeNoError ErrCode = 0x0 | ||
| ErrCodeProtocol ErrCode = 0x1 | ||
| ErrCodeInternal ErrCode = 0x2 | ||
| ErrCodeFlowControl ErrCode = 0x3 | ||
| ErrCodeSettingsTimeout ErrCode = 0x4 | ||
| ErrCodeStreamClosed ErrCode = 0x5 | ||
| ErrCodeFrameSize ErrCode = 0x6 | ||
| ErrCodeRefusedStream ErrCode = 0x7 | ||
| ErrCodeCancel ErrCode = 0x8 | ||
| ErrCodeCompression ErrCode = 0x9 | ||
| ErrCodeConnect ErrCode = 0xa | ||
| ErrCodeEnhanceYourCalm ErrCode = 0xb | ||
| ErrCodeIndaequateSecurity ErrCode = 0xc | ||
| ErrCodeHTTP11Required ErrCode = 0xd | ||
| ) | ||
|
|
||
| var errorCodeNames = map[ErrCode]string{ | ||
| ErrCodeNoError: "NO_ERROR", | ||
| ErrCodeProtocol: "PROTOCOL_ERROR", | ||
| ErrCodeInternal: "INTERNAL_ERROR", | ||
| ErrCodeFlowControl: "FLOW_CONTROL_ERROR", | ||
| ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT", | ||
| ErrCodeStreamClosed: "STREAM_CLOSED", | ||
| ErrCodeFrameSize: "FRAME_SIZE_ERROR", | ||
| ErrCodeRefusedStream: "REFUSED_STREAM", | ||
| ErrCodeCancel: "CANCEL", | ||
| ErrCodeCompression: "COMPRESSION_ERROR", | ||
| ErrCodeConnect: "CONNECT_ERROR", | ||
| ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM", | ||
| ErrCodeIndaequateSecurity: "INADEQUATE_SECURITY", | ||
| ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED", | ||
| } | ||
|
|
||
| func (err ErrCode) String() string { | ||
| if v, ok := errorCodeNames[err]; ok { | ||
| return v | ||
| } | ||
| return fmt.Sprintf("unknown error code 0x%x", uint32(err)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package grpchttp2 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "google.golang.org/grpc/internal/grpctest" | ||
| ) | ||
|
|
||
| type s struct { | ||
| grpctest.Tester | ||
| } | ||
|
|
||
| func Test(t *testing.T) { | ||
| grpctest.RunSubTests(t, s{}) | ||
| } | ||
|
|
||
| func (s) TestErrorCodeString(t *testing.T) { | ||
| errCodesTest := []struct { | ||
easwars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| err ErrCode | ||
| want string | ||
| }{ | ||
| {ErrCodeNoError, "NO_ERROR"}, | ||
easwars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {ErrCodeProtocol, "PROTOCOL_ERROR"}, | ||
| {ErrCodeInternal, "INTERNAL_ERROR"}, | ||
| {ErrCodeFlowControl, "FLOW_CONTROL_ERROR"}, | ||
| {ErrCodeSettingsTimeout, "SETTINGS_TIMEOUT"}, | ||
| {ErrCodeStreamClosed, "STREAM_CLOSED"}, | ||
| {ErrCodeFrameSize, "FRAME_SIZE_ERROR"}, | ||
| {ErrCodeRefusedStream, "REFUSED_STREAM"}, | ||
| {ErrCodeCancel, "CANCEL"}, | ||
| {ErrCodeCompression, "COMPRESSION_ERROR"}, | ||
| {ErrCodeConnect, "CONNECT_ERROR"}, | ||
| {ErrCodeEnhanceYourCalm, "ENHANCE_YOUR_CALM"}, | ||
| {ErrCodeIndaequateSecurity, "INADEQUATE_SECURITY"}, | ||
| {ErrCodeHTTP11Required, "HTTP_1_1_REQUIRED"}, | ||
| {ErrCode(0x1), "PROTOCOL_ERROR"}, | ||
| {ErrCode(0xf), "unknown error code 0xf"}, | ||
| } | ||
|
|
||
| for _, errTest := range errCodesTest { | ||
easwars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if errTest.err.String() != errTest.want { | ||
| t.Errorf("got %q, want %q", errTest.err.String(), errTest.want) | ||
easwars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.