use of ratpack.http.internal.DefaultRequest in project ratpack by ratpack.
the class DefaultRequestFixture method invoke.
private HandlingResult invoke(Handler handler, Registry registry, DefaultHandlingResult.ResultsHolder results) throws HandlerTimeoutException {
ServerConfig serverConfig = registry.get(ServerConfig.class);
DefaultRequest request = new DefaultRequest(Instant.now(), requestHeaders, HttpMethod.valueOf(method.toUpperCase()), HttpVersion.valueOf(protocol), uri, new InetSocketAddress(remoteHostAndPort.getHost(), remoteHostAndPort.getPort()), new InetSocketAddress(localHostAndPort.getHost(), localHostAndPort.getPort()), serverConfig, new RequestBodyReader() {
private boolean unread = true;
private long maxContentLength = 8096;
public boolean isUnread() {
return unread;
}
@Override
public long getContentLength() {
return requestBody.readableBytes();
}
@Override
public long getMaxContentLength() {
return maxContentLength;
}
@Override
public void setMaxContentLength(long maxContentLength) {
this.maxContentLength = maxContentLength;
}
@Override
public Promise<? extends ByteBuf> read(Block onTooLarge) {
return Promise.sync(() -> {
unread = false;
return requestBody;
}).route(r -> r.readableBytes() > maxContentLength, onTooLarge.action());
}
@Override
public TransformablePublisher<? extends ByteBuf> readStream() {
return Streams.publish(Collections.singleton(requestBody)).wiretap(e -> unread = false);
}
}, idleTimeout -> {
}, null);
if (pathBinding != null) {
handler = Handlers.chain(ctx -> {
ctx.getExecution().get(PathBindingStorage.TYPE).push(pathBinding);
ctx.next();
}, handler);
}
try {
return new DefaultHandlingResult(request, results, responseHeaders, registry, timeout, handler);
} catch (Exception e) {
throw Exceptions.uncheck(e);
} finally {
registry.get(ExecController.class).close();
}
}
Aggregations