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

415 Error When Setting Content-Type Header with Request Header #40

Open
madhurkapadia opened this issue Jul 22, 2024 · 5 comments
Open

Comments

@madhurkapadia
Copy link

madhurkapadia commented Jul 22, 2024

Description:
I'm encountering a 415 (Unsupported Media Type) error when using Cronet to send requests with a request body and an explicitly set Content-Type header

Steps to Reproduce:
Create an OkHttp Request object with a non-empty RequestBody and set the "Content-Type" header to "application/json".
Use the Cronet library to send the request.
Observe a 415 error response from the server.

Expected Behavior:
The server should accept the request with the specified Content-Type and process the JSON payload.

Actual Behavior:
The server returns a 415 error, indicating that it doesn't support the provided Content-Type.

RequestResponseConverter class has

if (body.contentLength() != 0L) {
                if (okHttpRequest.header("Content-Type") == null && body.contentType() != null) {
                    builder.addHeader("Content-Type", body.contentType().toString());
                } else {
                    builder.addHeader("Content-Type", "application/octet-stream");
                }

                builder.setUploadDataProvider(this.requestBodyConverter.convertRequestBody(body, writeTimeoutMillis), this.uploadDataProviderExecutor);
            }

As the above check is incorrect and shouldn't replace Content-Type header with application/octet-stream blindly. It should respect whatever user is setting.

@madhurkapadia
Copy link
Author

can see in new code it has been already fixed

@madhurkapadia
Copy link
Author

Given the current issues, when are you planning to release an updated version?

@madhurkapadia madhurkapadia reopened this Jul 22, 2024
@Nek-12
Copy link

Nek-12 commented Sep 15, 2024

Currently blocked on using cronet because of this. Any response?

@juanfelippopeya
Copy link

any updates on this? when are you planning to release?

@yevon-cn
Copy link

@Danstahrg @google-admin any updates ? Like Commit 0a43782, It seems that the version in the Maven repository hasn't been updated for a long time.

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

No branches or pull requests

4 participants