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

"RpcError: missing response content type", but does it have to be there? #102

Closed
frederikhors opened this issue Apr 15, 2021 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@frederikhors
Copy link

frederikhors commented Apr 15, 2021

I don't know if this is a problem with this library or not.

I am building my backend server and I have the grpc route like this:

const router = new Router()

const routes = [
  router.Middleware(checkIfAuthenticated(IfNotReturn401())),
  router.Post("/api*", grpcWebServer())
]

When a request comes, the authentication middleware takes care of figuring out whether to proceed or not and if NOT it issues a response with a 401 status WITHOUT content-type header:

HTTP/1.1 401 Unauthorized
Access-Control-Allow-Origin: *
strict-transport-security: max-age=63072000; includeSubDomains; preload
x-content-type-options: nosniff
x-frame-options: Deny
date: Thu, 15 Apr 2021 11:52:53 GMT
content-length: 0
connection: close

But now I get this error:

RpcError: missing response content type
  at parseFormat (http://localhost:6000/node_modules/.vite/@protobuf-ts_grpcweb-transport.js?v=16e233eb:190:13)
  at readGrpcWebResponseHeader (http://localhost:6000/node_modules/.vite/@protobuf-ts_grpcweb-transport.js?v=16e233eb:116:51)
  at readGrpcWebResponseHeader (http://localhost:6000/node_modules/.vite/@protobuf-ts_grpcweb-transport.js?v=16e233eb:109:12)
  at http://localhost:6000/node_modules/.vite/@protobuf-ts_grpcweb-transport.js?v=16e233eb:373:34

Is this correct or should we handle this cases in parseFormat()?

timostamm added a commit that referenced this issue Apr 15, 2021
Fixed grpcweb-transport to handle responses with HTTP error status and missing content-type header.

Breaking changes:

The function `readGrpcWebResponseHeader()` no longer returns the format.

The function `readGrpcWebResponseBody()` no longer takes the format as an argument. Instead, it now takes the content-type response header value and determines the format on its own.
@timostamm timostamm added the bug Something isn't working label Apr 15, 2021
@timostamm
Copy link
Owner

gRPC-web transport should detect HTTP 401 and raise a GrpcError UNAUTHENTICATED. It should not fall on its face because of the omitted header in this case.

@timostamm
Copy link
Owner

Thanks for the bug report, @frederikhors !

Fix is published in v2.0.0-alpha.20, available in the "next" channel.

Could you verify if this fixes the problem?

@frederikhors
Copy link
Author

I'll check immediately.

I love you and protobuf-ts immensely!

@frederikhors
Copy link
Author

It works!!!!! Thanks! ❤️

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

No branches or pull requests

2 participants