use of org.webpieces.router.impl.dto.RenderStaticResponse in project webpieces by deanhiller.
the class XFileReader method runFileRead.
public XFuture<Void> runFileRead(RequestInfo info, RenderStaticResponse renderStatic, ProxyStreamHandle handle) throws IOException {
VirtualFile fullFilePath = renderStatic.getFilePath();
if (!fullFilePath.exists()) {
throw new NotFoundException("File not found=" + fullFilePath);
} else if (fullFilePath.isDirectory()) {
throw new NotFoundException("File not found (it was a directory that can't be rendered)=" + fullFilePath);
}
String fileName = getNameToUse(fullFilePath);
String extension = null;
int lastDot = fileName.lastIndexOf(".");
if (lastDot > 0) {
extension = fileName.substring(lastDot + 1);
}
ResponseCreator.ResponseEncodingTuple tuple = responseCreator.createResponse(info.getRequest(), StatusCode.HTTP_200_OK, extension, "application/octet-stream", false);
Http2Response response = tuple.response;
// On startup, we protect developers from breaking clients. In http, all files that change
// must also change the hash automatically and the %%{ }%% tag generates those hashes so the
// files loaded are always the latest
Long timeSeconds = config.getStaticFileCacheTimeSeconds();
if (timeSeconds != null)
response.addHeader(new Http2Header(Http2HeaderName.CACHE_CONTROL, "max-age=" + timeSeconds));
ChunkReader reader = createFileReader(response, renderStatic, fileName, fullFilePath, info, extension, tuple, handle);
if (log.isDebugEnabled())
log.debug("sending chunked file via async read=" + reader);
ProxyStreamHandle stream = info.getResponseSender();
return futureUtil.finallyBlock(() -> stream.process(response).thenCompose(s -> readLoop(s, info.getPool(), reader, 0)), () -> handleClose(info, reader));
}
use of org.webpieces.router.impl.dto.RenderStaticResponse in project webpieces by deanhiller.
the class RouteInvokerStatic method invokeStatic.
public RouterStreamRef invokeStatic(RequestContext ctx, ProxyStreamHandle handler, RouteInfoForStatic data) {
boolean isOnClassPath = data.isOnClassPath();
RenderStaticResponse resp = new RenderStaticResponse(data.getTargetCacheLocation(), isOnClassPath);
// we do have a test for this now if you try to fix it
if (data.isRouteAFile()) {
resp.setFilePath(data.getFileSystemPath());
} else {
String relativeUrl = ctx.getPathParams().get("resource");
if (// make it truly relative so it does not start with /
relativeUrl.startsWith("/"))
relativeUrl = relativeUrl.substring(1);
VirtualFile fullPath = data.getFileSystemPath().child(relativeUrl);
resp.setFileAndRelativePath(fullPath, relativeUrl);
}
ResponseStaticProcessor processor = new ResponseStaticProcessor(reader, pool, futureUtil, ctx, handler);
return processor.renderStaticResponse(resp);
}
Aggregations