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

ErrorWriter does not respect connect.WithRequireConnectProtocolHeader option #699

Closed
weeco opened this issue Feb 22, 2024 · 0 comments · Fixed by #700
Closed

ErrorWriter does not respect connect.WithRequireConnectProtocolHeader option #699

weeco opened this issue Feb 22, 2024 · 0 comments · Fixed by #700
Assignees
Labels
bug Something isn't working

Comments

@weeco
Copy link

weeco commented Feb 22, 2024

Describe the bug

I'm using the gRPC gateway and want to use the errorWriter only for non-HTTP (connect/gRPC) methods. Unfortunately the IsSupported() method yields true in too many cases (i.e. REST client sends application/json content type). Thus I cannot differentiate between HTTP and connect/grpc using the error writer.

I hoped the opt connect.WithRequireConnectProtocolHeader() would help me with that, but it seems to be not considered.

		connect.NewErrorWriter(connect.WithRequireConnectProtocolHeader())
		if errorWriter.IsSupported(r) {
			_ = errorWriter.Write(w, r, connectErr)
		} else {
			apierrors.HandleHTTPError(r.Context(), w, r, connectErr)
		}

To Reproduce

See above snippet.

Environment (please complete the following information):

  • connect-go version or commit: connectrpc.com/connect v1.14.0
  • go version: (for example, go version go1.18.3 darwin/amd64) v1.22.0

Additional context

Slack thread: https://bufbuild.slack.com/archives/CRZ680FUH/p1708557962229309
Related issue: #689

@weeco weeco added the bug Something isn't working label Feb 22, 2024
emcfarlane added a commit that referenced this issue Feb 23, 2024
This PR fixes ErrorWriter to correctly return unsupported protocol if
the option WithRequireConnectProtocolHeader is set and the header or
query value isn't include in the request. It will now correctly return
unsupported to ensure fallback options can process the error.

Fixes #699
@emcfarlane emcfarlane self-assigned this Feb 23, 2024
emcfarlane added a commit that referenced this issue Mar 6, 2024
#700)

This PR fixes ErrorWriter to correctly return unsupported protocol if
the option `WithRequireConnectProtocolHeader` is set and the header or
query value isn't include in the request. It will now correctly return
unsupported to ensure fallback options can process the error.

Fixes #699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants