use of io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE in project async-http-client by AsyncHttpClient.
the class BasicHttpsTest method multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy.
@Test
public void multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy() throws Throwable {
logger.debug(">>> multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy");
KeepAliveStrategy keepAliveStrategy = (ahcRequest, nettyRequest, nettyResponse) -> !ahcRequest.getUri().isSecured();
withClient(config().setSslEngineFactory(createSslEngineFactory()).setKeepAliveStrategy(keepAliveStrategy)).run(client -> withServer(server).run(server -> {
server.enqueueEcho();
server.enqueueEcho();
server.enqueueEcho();
String body = "hello there";
client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute();
client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute();
Response response = client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute().get();
assertEquals(response.getResponseBody(), body);
}));
logger.debug("<<< multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy");
}
use of io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE in project async-http-client by AsyncHttpClient.
the class BasicHttpsTest method reconnectAfterFailedCertificationPath.
@Test
public void reconnectAfterFailedCertificationPath() throws Throwable {
logger.debug(">>> reconnectAfterFailedCertificationPath");
AtomicBoolean trust = new AtomicBoolean();
withClient(config().setMaxRequestRetry(0).setSslEngineFactory(createSslEngineFactory(trust))).run(client -> withServer(server).run(server -> {
server.enqueueEcho();
server.enqueueEcho();
String body = "hello there";
// first request fails because server certificate is rejected
Throwable cause = null;
try {
client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute().get(TIMEOUT, SECONDS);
} catch (final ExecutionException e) {
cause = e.getCause();
}
assertNotNull(cause);
// second request should succeed
trust.set(true);
Response response = client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute().get(TIMEOUT, SECONDS);
assertEquals(response.getResponseBody(), body);
}));
logger.debug("<<< reconnectAfterFailedCertificationPath");
}
use of io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE in project cf-java-client by cloudfoundry.
the class MultipartHttpClientRequest method done.
public Mono<Void> done() {
AsciiString boundary = generateMultipartBoundary();
AsciiString delimiter = getDelimiter(boundary);
AsciiString closeDelimiter = getCloseDelimiter(boundary);
List<PartHttpClientRequest> parts = this.partConsumers.stream().map(partConsumer -> {
PartHttpClientRequest part = new PartHttpClientRequest(this.objectMapper);
partConsumer.accept(part);
return part;
}).collect(Collectors.toList());
Long contentLength = parts.stream().mapToLong(part -> delimiter.length() + CRLF.length() + part.getLength()).sum() + closeDelimiter.length();
NettyOutbound intermediateRequest = this.request.chunkedTransfer(false).header(CONTENT_TYPE, BOUNDARY_PREAMBLE.concat(boundary)).header(CONTENT_LENGTH, String.valueOf(contentLength));
for (PartHttpClientRequest part : parts) {
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(delimiter.toByteArray()));
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(CRLF.toByteArray()));
intermediateRequest = intermediateRequest.sendObject(part.renderedHeaders);
intermediateRequest = part.sendPayload(intermediateRequest);
}
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(closeDelimiter.toByteArray()));
return intermediateRequest.then();
}
Aggregations