Search in sources :

Example 1 with HttpStatus

use of com.generallycloud.baseio.codec.http11.future.HttpStatus in project baseio by generallycloud.

the class FutureAcceptorHttpFilter method accept404.

@Override
protected void accept404(SocketSession session, NamedFuture future, String serviceName) throws IOException {
    HttpEntity entity = html_cache.get(serviceName);
    HttpStatus status = HttpStatus.C200;
    ServerHttpFuture f = (ServerHttpFuture) future;
    if (entity == null) {
        f.setStatus(HttpStatus.C404);
        entity = html_cache.get("/404.html");
        if (entity == null) {
            super.accept404(session, f, serviceName);
            return;
        }
    }
    File file = entity.getFile();
    if (file != null && file.lastModified() > entity.getLastModify()) {
        synchronized (entity) {
            reloadEntity(entity, session.getContext(), status);
        }
        flush(session, f, entity);
        return;
    }
    String ims = f.getRequestHeader(HttpHeader.IF_MODIFIED_SINCE);
    long imsTime = -1;
    if (!StringUtil.isNullOrBlank(ims)) {
        imsTime = HttpHeaderDateFormat.getFormat().parse(ims).getTime();
    }
    if (imsTime < entity.getLastModifyGTMTime()) {
        flush(session, f, entity);
        return;
    }
    f.setStatus(HttpStatus.C304);
    session.flush(f);
}
Also used : HttpStatus(com.generallycloud.baseio.codec.http11.future.HttpStatus) ServerHttpFuture(com.generallycloud.baseio.codec.http11.future.ServerHttpFuture) File(java.io.File)

Aggregations

HttpStatus (com.generallycloud.baseio.codec.http11.future.HttpStatus)1 ServerHttpFuture (com.generallycloud.baseio.codec.http11.future.ServerHttpFuture)1 File (java.io.File)1