use of act.ActResponse in project actframework by actframework.
the class FileGetter method handle.
@Override
public void handle(ActionContext context) {
if (null != delegate) {
delegate.handle(context);
return;
}
context.handler(this);
File file = base;
H.Format fmt;
if (base.isDirectory()) {
String path = context.paramVal(ParamNames.PATH);
if (S.blank(path)) {
AlwaysForbidden.INSTANCE.handle(context);
return;
}
file = new File(base, path);
if (!file.exists()) {
AlwaysNotFound.INSTANCE.handle(context);
return;
}
if (file.isDirectory() || !file.canRead()) {
AlwaysForbidden.INSTANCE.handle(context);
return;
}
}
ActResponse resp = context.prepareRespForWrite();
fmt = contentType(file.getPath());
resp.contentType(fmt);
context.applyCorsSpec().applyContentSecurityPolicy().applyContentType();
InputStream is = new BufferedInputStream(IO.is(file));
IO.copy(is, resp.outputStream());
}
Aggregations