Skip to content
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

Fix ErrorWriter connect GET protocol classifier #654

Merged
merged 5 commits into from
Dec 22, 2023

Conversation

emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Dec 12, 2023

ErrorWriter will now correctly classifying connect GET requests if the connect protocol version header is present or the connect protocol version is set in the URL query parameters. To handle connect GET requests without the protocol version the ErrorWriter will write errors as connect unary errors if the protocol is unknown. This ensures the error is always written to the client. The connect unary error payload is always in JSON and therefore makes a nice human-readable format for the caller. Clients are still recommended to check IsSupported first to ensure the protocol will match the desired and to provide fallback to other error writers if desired.

Fix for #637 . Defaults to connect unary errors. To support other fallbacks use the (*ErrorWriter).IsSupported() check before calling (*ErrorWriter).Write(err).

ErrorWriter will now correctly classifying connect GET requests if
the connect protocol version header is present or the connect protocol
version is set in the URL query parameters. To handle connect GET
requests without the protocol version the ErrorWriter will write errors
as connect unary errors if the protocol is unknown. This ensures the
error is written to the client. The connect unary error payload is
always in JSON and therefore human-readable to the caller. Clients are
still recommended to check `IsSupported` first to ensure the protocol
will match the desired and to provide fallback to other error writers.
@@ -394,6 +394,14 @@ func TestServer(t *testing.T) {
connect.WithSendGzip(),
)
})
t.Run("json_get", func(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a test case I've extended TestServer to include an option with GET set. We exercise error writer in the middleware tests and this covers the case with ping as a GET and a large ping as a fallback to POST.

error_writer.go Outdated Show resolved Hide resolved
@jhump
Copy link
Member

jhump commented Dec 13, 2023

It appears this would also address #637. I think the only potentially controversial part in here is the change to always fall back to the Connect protocol's JSON error format output even when the incoming protocol cannot be determined. I'm okay with it, but am curious if @akshayjshah or @mattrobenolt have objections.

@mattrobenolt
Copy link
Contributor

I think this is fine. This behavior wouldn't affect us. I use ErrorWriter.IsSupported() to spit back a plaintext error, and we don't use GET requests for anything.

error_writer.go Outdated Show resolved Hide resolved
Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is great! Supporting GETs was an unfortunate oversight, and defaulting to JSON makes sense. A few nits about the code structure and comments, but I'd love to get this landed and released ASAP :)

error_writer.go Outdated Show resolved Hide resolved
error_writer.go Outdated Show resolved Hide resolved
@bufdev bufdev merged commit 10c36bf into connectrpc:main Dec 22, 2023
11 checks passed
@emcfarlane emcfarlane deleted the fixErrorWriterGET branch December 22, 2023 16:44
emcfarlane added a commit to emcfarlane/connect-go that referenced this pull request Jan 1, 2024
`ErrorWriter` will now correctly classifying connect GET requests if the
connect protocol version header is present or the connect protocol
version is set in the URL query parameters. To handle connect GET
requests without the protocol version the ErrorWriter will write errors
as connect unary errors if the protocol is unknown. This ensures the
error is always written to the client. The connect unary error payload
is always in JSON and therefore makes a nice human-readable format for
the caller. Clients are still recommended to check `IsSupported` first
to ensure the protocol will match the desired and to provide fallback to
other error writers if desired.

Fix for connectrpc#637 . Defaults to connect unary errors. To support other
fallbacks use the `(*ErrorWriter).IsSupported()` check before calling
`(*ErrorWriter).Write(err)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants