use of io.undertow.protocols.http2.Http2DataStreamSinkChannel in project undertow by undertow-io.
the class Http2ReceiveListener method handleInitialRequest.
/**
* Handles the initial request when the exchange was started by a HTTP ugprade.
*
*
* @param initial The initial upgrade request that started the HTTP2 connection
*/
void handleInitialRequest(HttpServerExchange initial, Http2Channel channel) {
//we have a request
Http2HeadersStreamSinkChannel sink = channel.createInitialUpgradeResponseStream();
final Http2ServerConnection connection = new Http2ServerConnection(channel, sink, undertowOptions, bufferSize, rootHandler);
HeaderMap requestHeaders = new HeaderMap();
for (HeaderValues hv : initial.getRequestHeaders()) {
requestHeaders.putAll(hv.getHeaderName(), hv);
}
final HttpServerExchange exchange = new HttpServerExchange(connection, requestHeaders, sink.getHeaders(), maxEntitySize);
connection.setExchange(exchange);
exchange.setRequestScheme(initial.getRequestScheme());
exchange.setProtocol(initial.getProtocol());
exchange.setRequestMethod(initial.getRequestMethod());
exchange.setQueryString(initial.getQueryString());
String uri = exchange.getQueryString().isEmpty() ? initial.getRequestURI() : initial.getRequestURI() + '?' + exchange.getQueryString();
try {
Connectors.setExchangeRequestPath(exchange, uri, encoding, decode, allowEncodingSlash, decodeBuffer, maxParameters);
} catch (ParameterLimitException e) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
SSLSession session = channel.getSslSession();
if (session != null) {
connection.setSslSessionInfo(new Http2SslSessionInfo(channel));
}
Connectors.terminateRequest(exchange);
sink.setCompletionListener(new ChannelListener<Http2DataStreamSinkChannel>() {
@Override
public void handleEvent(Http2DataStreamSinkChannel channel) {
Connectors.terminateResponse(exchange);
}
});
Connectors.executeRootHandler(rootHandler, exchange);
}
use of io.undertow.protocols.http2.Http2DataStreamSinkChannel in project undertow by undertow-io.
the class Http2ReceiveListener method handleCommonSetup.
private void handleCommonSetup(Http2HeadersStreamSinkChannel sink, HttpServerExchange exchange, Http2ServerConnection connection) {
Http2Channel channel = sink.getChannel();
SSLSession session = channel.getSslSession();
if (session != null) {
connection.setSslSessionInfo(new Http2SslSessionInfo(channel));
}
sink.setTrailersProducer(new Http2DataStreamSinkChannel.TrailersProducer() {
@Override
public HeaderMap getTrailers() {
Supplier<HeaderMap> supplier = exchange.getAttachment(HttpAttachments.RESPONSE_TRAILER_SUPPLIER);
if (supplier != null) {
return supplier.get();
}
return exchange.getAttachment(HttpAttachments.RESPONSE_TRAILERS);
}
});
sink.setCompletionListener(new ChannelListener<Http2DataStreamSinkChannel>() {
@Override
public void handleEvent(Http2DataStreamSinkChannel channel) {
Connectors.terminateResponse(exchange);
}
});
exchange.setProtocol(Protocols.HTTP_2_0);
if (exchange.getRequestMethod().equals(Methods.HEAD)) {
exchange.addResponseWrapper(new ConduitWrapper<StreamSinkConduit>() {
@Override
public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) {
return new HeadStreamSinkConduit(factory.create(), null, true);
}
});
}
}
use of io.undertow.protocols.http2.Http2DataStreamSinkChannel in project undertow by undertow-io.
the class Http2ServerConnection method pushResource.
@Override
public boolean pushResource(String path, HttpString method, HeaderMap requestHeaders, final HttpHandler handler) {
HeaderMap responseHeaders = new HeaderMap();
try {
requestHeaders.put(METHOD, method.toString());
requestHeaders.put(PATH, path.toString());
requestHeaders.put(AUTHORITY, exchange.getHostAndPort());
requestHeaders.put(SCHEME, exchange.getRequestScheme());
Http2HeadersStreamSinkChannel sink = channel.sendPushPromise(responseChannel.getStreamId(), requestHeaders, responseHeaders);
Http2ServerConnection newConnection = new Http2ServerConnection(channel, sink, getUndertowOptions(), getBufferSize(), rootHandler);
final HttpServerExchange exchange = new HttpServerExchange(newConnection, requestHeaders, responseHeaders, getUndertowOptions().get(UndertowOptions.MAX_ENTITY_SIZE, UndertowOptions.DEFAULT_MAX_ENTITY_SIZE));
newConnection.setExchange(exchange);
exchange.setRequestMethod(method);
exchange.setProtocol(Protocols.HTTP_1_1);
exchange.setRequestScheme(this.exchange.getRequestScheme());
try {
Connectors.setExchangeRequestPath(exchange, path, getUndertowOptions().get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name()), getUndertowOptions().get(UndertowOptions.DECODE_URL, true), getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false), new StringBuilder(), getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_HEADERS));
} catch (ParameterLimitException e) {
UndertowLogger.REQUEST_IO_LOGGER.debug("Too many parameters in HTTP/2 request", e);
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return false;
}
sink.setCompletionListener(new ChannelListener<Http2DataStreamSinkChannel>() {
@Override
public void handleEvent(Http2DataStreamSinkChannel channel) {
Connectors.terminateResponse(exchange);
}
});
Connectors.terminateRequest(exchange);
getIoThread().execute(new Runnable() {
@Override
public void run() {
Connectors.executeRootHandler(handler, exchange);
}
});
return true;
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
return false;
}
}
Aggregations