-
Notifications
You must be signed in to change notification settings - Fork 24k
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
[Network] Android throws up a redbox when POST has no body #3371
Comments
The error is being generated by OkHTTP, so we should change this in the call site. |
I looked into this and OkHttp doesn't make it very easy to fix the caller since the HttpMethods class is internal and that's what they use to determine whether to require a body (or require no body). Changing the caller does look like the right fix though -- three ideas are:
|
Their required Polyfilling the body doesn't sound like a bad idea. Will the error subside if we supply a body argument with an empty string? The issue sounds to primarily exist due to the absence of a request body, versus it being empty, as described in square/okhttp#751. And it doesn't sound like there will be support in the library based on the HTTP spec requiring a request body. |
I prefer option 3 in the list above. It's so much better when the native layer is robust and doesn't throw assertions when JS send it unexpected commands, and we also want to make the JS API (XHR polyfill in this case) convenient to use. |
Yeah, very valid. The underlying system shouldn't fail for this unexpected input. So it sounds like this should be twofold --
As a follow-on, it may be good to look at this behavior for other requests that may expect a request body, like |
This is the logic that OkHttp uses https://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpMethod.java#L27 I wish they made this part of their public API so we wouldn't have to replicate it but it's very simple code fortunately. |
Yeahhh, i ran into this when debugging the |
We should handle the other HTTP methods too. I don't feel strongly about the PROPPATCH and REPORT methods but they're simple to support so why not? |
On second thought, it would make sense to add polyfill support for those additional 2. +1 on supporting all 5. |
Any update here? :) Perhaps @ide |
the same error in HTTP PUT request. |
Relatedly,
|
if (data == null) {
if(method.equals("POST")
|| method.equals("PUT")
|| method.equals("PATCH")){
requestBuilder.method(method, RequestBody.create(null, new byte[0]));
} else {
requestBuilder.method(method, null);
}
} @ide this would do? |
basically copy-pasted the method 'HttpMethod.requiresRequestBody' from https://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpMethod.java#L27 |
This occurs when you make a call like
fetch(url, { method: 'post' })
. The native layer should fill in an empty body instead of fataling.The text was updated successfully, but these errors were encountered: