@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
// We don't support GET.
if (!request.getHttpMethod().equals(GET)) {
return Observable.error(new HttpError(METHOD_NOT_ALLOWED));
}
RandomAccessFile raf = null;
String sanitizedUri = sanitizeUri(request.getUri());
if (sanitizedUri == null) {
return Observable.error(new HttpError(FORBIDDEN));
}
URI uri = resolveUri(sanitizedUri);
if (uri == null) {
return Observable.error(new HttpError(NOT_FOUND));
}
File file = new File(uri);
if (file.isHidden() || !file.exists()) {
return Observable.error(new HttpError(NOT_FOUND));
}
if (file.isDirectory()) {
return Observable.error(new HttpError(FORBIDDEN));
}
if (!file.isFile()) {
return Observable.error(new HttpError(FORBIDDEN));
}
long fileLength;
try {
raf = new RandomAccessFile(file, "r");