-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Provide an opt-in zero-copy response body view #2322
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
base: main
Are you sure you want to change the base?
Changes from all commits
f0821dd
eb067d8
64bc6ce
156282c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,39 @@ | |
| */ | ||
| byte[] getResponseBodyAsBytes(); | ||
|
|
||
| /** | ||
| * Returns the entire response body as a byte array whose storage the implementation may share with whatever | ||
| * else holds the body. | ||
| * | ||
| * <p>The returned array must be treated as read-only, and the response is not its only holder. Where it is a | ||
| * body part's own array, it is the array reachable from the part handed to | ||
| * {@link AsyncHandler#onBodyPartReceived}, the one each | ||
| * {@link org.asynchttpclient.handler.TransferListener} is given by a | ||
| * {@link org.asynchttpclient.handler.TransferCompletionHandler}, and the one | ||
| * {@link #getResponseBodyAsByteBuf()} wraps. Writing to it changes what all of those see, and a write | ||
| * through any of them changes what this returns. | ||
| * | ||
| * <p>Whether anything is shared at all is not something to rely on. It depends on how the body happened to | ||
| * arrive - how the origin chunked it, whether a proxy re-chunked it, whether it was compressed - and on the | ||
| * body parts the implementation was given, none of which is visible from here. The same body from the | ||
| * same server may be shared on one response and copied on the next. No array identity is guaranteed between | ||
| * calls either. | ||
| * | ||
| * <p>A caller that needs an array it may modify should copy what it receives. {@link | ||
| * #getResponseBodyAsBytes()} is the accessor to reach for first, but it is implemented by whoever implements | ||
| * this interface, so read its contract rather than assuming it hands over an array of its own. | ||
| * | ||
| * <p>Implementation note: the default implementation of this method returns | ||
| * {@link #getResponseBodyAsBytes()}. An implementation that leaves that default in place must not implement | ||
| * {@code getResponseBodyAsBytes()} in terms of this method, or the two call each other. Overriding both is | ||
| * fine. | ||
| * | ||
| * @return the entire response body, possibly sharing storage with the response | ||
| */ | ||
| default byte[] getResponseBodyAsBytesView() { | ||
| return getResponseBodyAsBytes(); | ||
| } | ||
|
|
||
| /** | ||
| * Return the entire response body as a ByteBuffer. | ||
| * | ||
|
|
@@ -106,7 +139,7 @@ | |
| String getContentType(); | ||
|
|
||
| /** | ||
| * @param name the header name | ||
|
Check warning on line 142 in client/src/main/java/org/asynchttpclient/Response.java
|
||
| * @return the first response header value | ||
| */ | ||
| String getHeader(CharSequence name); | ||
|
|
@@ -137,7 +170,7 @@ | |
| String toString(); | ||
|
|
||
| /** | ||
| * @return the list of {@link Cookie}. | ||
|
Check warning on line 173 in client/src/main/java/org/asynchttpclient/Response.java
|
||
| */ | ||
| List<Cookie> getCookies(); | ||
|
|
||
|
|
@@ -206,7 +239,7 @@ | |
| } | ||
|
|
||
| /** | ||
| * @param bodyPart a body part (possibly empty, but will be filtered out) | ||
|
Check warning on line 242 in client/src/main/java/org/asynchttpclient/Response.java
|
||
| */ | ||
| public void accumulate(HttpResponseBodyPart bodyPart) { | ||
| if (bodyPart.length() > 0) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.