public AutoCloseable send(SimpleHttpClientHandler handler) {
return finish().send(handler);
}
public Finished finish() {
final HttpClient onClient;
final boolean shouldCloseClient;
final Queue q;
final boolean shouldCloseQueue;
if (client == null) {
if (queue == null) {
try {
q = new Queue();
} catch (IOException e) {
LOGGER.error("Queue could not be created", e);
return null;
}
shouldCloseQueue = true;
} else {
q = queue;
shouldCloseQueue = false;
}
onClient = new HttpClient(q, trust);
shouldCloseClient = true;
} else {
onClient = client;
shouldCloseClient = false;
q = null;
shouldCloseQueue = false;
}
return new Finished() {
@Override
public void close() {
if (shouldCloseQueue) {
q.close();
}
if (shouldCloseClient) {
onClient.close();
}
}
@Override
public Finished send(final SimpleHttpClientHandler handler) {
final Address a;
if (host != null) {
if (port < 0) {
a = new Address(host, secure ? Http.DEFAULT_SECURE_PORT : Http.DEFAULT_PORT);
} else {
a = new Address(host, port);
}
} else {
a = address;
}
if (post != null) {
method = HttpRequest.Method.POST;
}
HttpRequest request = new HttpRequest(a, secure, method, path);
if (post != null) {
request.getHeaders().put(Http.CONTENT_LENGTH, String.valueOf(post.remaining()));
}
onClient.send(request, new HttpClientHandler() {
private HttpResponse response = null;
private InMemoryPost body = null;
@Override
public void ready(ByteBufferHandler write) {