-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Simple netty based HttpClient #27881
Conversation
API changes have been detected in |
API changes have been detected in API changes + public class SimpleNettyHttpClient implements HttpClient {
+ public SimpleNettyHttpClient()
+ @Override public Mono<HttpResponse> send(HttpRequest request)
+ @Override public Mono<HttpResponse> send(HttpRequest request, Context context)
+ @Override public HttpResponse sendSynchronously(HttpRequest request, Context context)
+ } |
API changes have been detected in |
outputStream = new ByteArrayOutputStream(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A recommendation in "Effective Java (EJ)" while following DCL is to introduce a local variable. As per the EJ, such a version may improve the perf by about 25% compared to the version without the local variable.
The code would be (pattern copied from EJ)
public void collect(ByteBuf buffer, boolean isLast) {
if (buffer.isReadable()) {
ByteArrayOutputStream result = ensureStream();
try {
buffer.readBytes(result, buffer.readableBytes());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
private ByteArrayOutputStream ensureStream() {
ByteArrayOutputStream result = outputStream;
if (result == null) {
synchronized (this) {
result = outputStream;
if (result == null) {
outputStream = result = new ByteArrayOutputStream();
}
}
}
return result;
}
This PR has a prototype of a lightweight
HttpClient
based onNetty
.This prototype aims to build an http client that works for various types of payloads and context (sync vs async) and mostly serve sunny day scenarios while introducing all the required complexities to do so.
There's a lot of corner (mostly error) cases that remain uncovered here, but they likely won't affect existing complexity much.
Implemented features:
CompletableFeature
instead.The client seems to be functional, i.e.
SimpleNettyHttpClientHttpClientTests extends HttpClientTests
andSimpleNettyHttpClientRestProxyTests extends RestProxyTests
are passing.