Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixing Content-Type bug for HTTP/1.1 POST Unary requests in Unity #41

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

ShikiGami
Copy link
Contributor

As described in #39 , there is a bug when trying to create Unary requests from Unity.
At the server side, the request content type will appear as application/octet-stream instead of the expected application/grpc-web which will not allow the GrpcWebSocketBridge middleware to execute properly because of this condition:

if (!HttpMethods.IsPost(context.Request.Method) || context.Request.ContentType != "application/grpc-web")

The reason for this problem seems to be the implementation of the HTTP handler set for versions higher than Unity 2018.1, that uses UnityWebRequestHttpHandler.

In the implementation of UnityWebRequestHttpHandler, the Content Type seems to be set by the request accept header, but at no time in the creation of the request this header is set, instead the correct Content Type is set on the request content header "Content-Type".

I changed the implementation of UnityWebRequestHttpHandler to use this header.

Change Headers.Accept to Content.Headers.ContentType in order to get correct content type
Change Headers.Accept to Content.Headers.ContentType in order to get correct content type
@ShikiGami ShikiGami changed the title Fixing ContenType bug for HTTP/1.1 POST Unary requests in Unity Fixing Content-Type bug for HTTP/1.1 POST Unary requests in Unity Feb 2, 2025
@mayuki
Copy link
Member

mayuki commented Feb 6, 2025

Thanks! Looks good to me. 👍

@mayuki mayuki merged commit 46c1ed8 into Cysharp:main Feb 6, 2025
2 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants