use of org.xnio.OptionMap in project undertow by undertow-io.
the class Http2ClientProvider method connect.
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
if (ssl == null) {
listener.failed(UndertowMessages.MESSAGES.sslWasNull());
return;
}
if (bindAddress == null) {
OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), options).addNotifier(createNotifier(listener), null);
} else {
ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, options), options).addNotifier(createNotifier(listener), null);
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class Http2UpgradeHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final String upgrade = exchange.getRequestHeaders().getFirst(Headers.UPGRADE);
if (upgrade != null && upgradeStrings.contains(upgrade)) {
String settings = exchange.getRequestHeaders().getFirst("HTTP2-Settings");
if (settings != null) {
//required by spec
final ByteBuffer settingsFrame = FlexBase64.decodeURL(settings);
exchange.getResponseHeaders().put(Headers.UPGRADE, upgrade);
exchange.upgradeChannel(new HttpUpgradeListener() {
@Override
public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
OptionMap undertowOptions = exchange.getConnection().getUndertowOptions();
Http2Channel channel = new Http2Channel(streamConnection, upgrade, exchange.getConnection().getByteBufferPool(), null, false, true, true, settingsFrame, undertowOptions);
Http2ReceiveListener receiveListener = new Http2ReceiveListener(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
//as the request was only to create the initial request
if (exchange.getRequestHeaders().contains("X-HTTP2-connect-only")) {
exchange.endExchange();
return;
}
exchange.setProtocol(Protocols.HTTP_2_0);
next.handleRequest(exchange);
}
}, undertowOptions, exchange.getConnection().getBufferSize(), null);
channel.getReceiveSetter().set(receiveListener);
receiveListener.handleInitialRequest(exchange, channel);
channel.resumeReceives();
}
});
return;
}
}
next.handleRequest(exchange);
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class MaxRequestSizeTestCase method testMaxRequestEntitySize.
@Test
public void testMaxRequestEntitySize() throws IOException {
OptionMap existing = DefaultServer.getUndertowOptions();
final TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
post.setEntity(new StringEntity(A_MESSAGE));
post.addHeader(Headers.CONNECTION_STRING, "close");
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
OptionMap maxSize = OptionMap.create(UndertowOptions.MAX_ENTITY_SIZE, (long) A_MESSAGE.length() - 1);
DefaultServer.setUndertowOptions(maxSize);
post = new HttpPost(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
post.setEntity(new StringEntity(A_MESSAGE));
result = client.execute(post);
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
maxSize = OptionMap.create(UndertowOptions.MAX_HEADER_SIZE, 1000);
DefaultServer.setUndertowOptions(maxSize);
post = new HttpPost(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
post.setEntity(new StringEntity(A_MESSAGE));
post.addHeader(Headers.CONNECTION_STRING, "close");
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class MaxRequestSizeTestCase method testMaxRequestHeaderSize.
@Test
public void testMaxRequestHeaderSize() throws IOException {
OptionMap existing = DefaultServer.getUndertowOptions();
final TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
post.setEntity(new StringEntity(A_MESSAGE));
post.addHeader(Headers.CONNECTION_STRING, "close");
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
OptionMap maxSize = OptionMap.create(UndertowOptions.MAX_HEADER_SIZE, 10);
DefaultServer.setUndertowOptions(maxSize);
try {
HttpResponse response = client.execute(post);
HttpClientUtils.readResponse(response);
Assert.assertEquals(StatusCodes.BAD_REQUEST, response.getStatusLine().getStatusCode());
} catch (IOException e) {
//expected
}
maxSize = OptionMap.create(UndertowOptions.MAX_HEADER_SIZE, 1000);
DefaultServer.setUndertowOptions(maxSize);
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class FixedLengthRequestTestCase method testMaxRequestSizeFixedLengthRequest.
@Test
@Ignore("sometimes the client attempts to re-use the same connection after the failure, but the server has already closed it")
public void testMaxRequestSizeFixedLengthRequest() throws IOException {
connection = null;
OptionMap existing = DefaultServer.getUndertowOptions();
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.setHeader(HttpHeaders.CONNECTION, "close");
TestHttpClient client = new TestHttpClient();
try {
generateMessage(1);
post.setEntity(new StringEntity(message));
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_ENTITY_SIZE, 3L));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
connection = null;
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_ENTITY_SIZE, (long) message.length()));
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
Aggregations