-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Stream bodies from first-party converters #3215
Comments
Looking at a PR for this but want to make sure I understand it correctly. Using Moshi as an example - should it work like this? @Override public RequestBody convert(final T value) {
return new RequestBody() {
@Override public MediaType contentType() {
return MEDIA_TYPE;
}
@Override public void writeTo(BufferedSink sink) throws IOException {
try (JsonWriter writer = JsonWriter.of(sink)) {
adapter.toJson(writer, value);
}
}
};
} |
Eh just went ahead and opened a PR #3220 |
Given the current state of Retrofit, does it make sense to revisit this and create factory methods that will expose the ability to stream request bodies? |
In this comment:
But then here:
@JakeWharton The current behavior & API means you have to choose between "serializing lazily from the http thread" and "doing any kind of request signature". I seems to me it'd be beneficial to support both. What we really want is:
We don't necessarily need an API change to support this, but we'd definitely at least need an behavior change (or the option to do so), e.g. having the converter keep the same API but be called from a background thread. |
Retrofit has no threading so it is not possible to do both. Factory overloads to switch to streamed bodies instead of buffered bodies is really the only option. |
Depending on what execution mechanism you were using, it may be possible to apply threading earlier through a custom That's probably going to be pretty gross. However, an interceptor could also do this if someone really needed it. You build a new request with the original request body written to a |
This approach to fixing the converters is interesting: https://gist.github.com/cbeyls/df12d51c427541eaffe1f6686e5480e2 It seems like this would fix the issue of not having content length, while making sure that's still computed on the http thread? |
We currently do not to guard against mutable inputs, but that doesn't seem worth optimizing for. Plus it defers even more work to the HTTP thread.
The text was updated successfully, but these errors were encountered: