Search in sources :

Example 1 with HttpStatus

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

the class HttpFrameHandle method printHtml.

protected void printHtml(Channel ch, Frame frame, HttpStatus status, String content) throws Exception {
    HttpFrame f = (HttpFrame) frame;
    StringBuilder builder = new StringBuilder(HttpUtil.HTML_HEADER);
    builder.append("        <div style=\"margin-left:20px;\">\n");
    builder.append("            ");
    builder.append(content);
    builder.append("            </div>\n");
    builder.append("        </div>\n");
    builder.append(HttpUtil.HTML_POWER_BY);
    builder.append(HttpUtil.HTML_BOTTOM);
    byte[] data = builder.toString().getBytes(ch.getCharset());
    f.setContent(data);
    f.setStatus(status);
    f.setContentType(HttpContentType.text_html_utf8);
    ch.writeAndFlush(f);
}
Also used : HttpFrame(com.firenio.codec.http11.HttpFrame)

Example 2 with HttpStatus

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

the class HttpFrameHandle method acceptHtml.

protected void acceptHtml(Channel ch, Frame frame) throws Exception {
    String frameName = HttpUtil.getFrameName(ch, frame);
    HttpEntity entity = null;
    if (frameName.equals("/")) {
        entity = htmlCache.get(welcome);
    }
    if (entity == null) {
        entity = htmlCache.get(frameName);
    }
    HttpStatus status = HttpStatus.C200;
    HttpFrame f = (HttpFrame) frame;
    if (entity == null) {
        entity = htmlCache.get("/404.html");
        if (entity == null) {
            printHtml(ch, frame, HttpStatus.C404, "404 page not found");
            return;
        }
    }
    File file = entity.getFile();
    if (file != null && file.lastModified() > entity.getLastModify()) {
        synchronized (entity) {
            if (file.lastModified() > entity.getLastModify()) {
                reloadEntity(entity, ch.getContext(), status);
            }
        }
        writeAndFlush(ch, f, entity);
        return;
    }
    String ims = f.getRequestHeader(HttpHeader.If_Modified_Since);
    long imsTime = -1;
    if (!Util.isNullOrBlank(ims)) {
        imsTime = DateUtil.get().parseHttp(ims).getTime();
    }
    if (imsTime < entity.getLastModifyGTMTime()) {
        writeAndFlush(ch, f, entity);
        return;
    }
    f.setStatus(HttpStatus.C304);
    ch.writeAndFlush(f);
}
Also used : HttpStatus(com.firenio.codec.http11.HttpStatus) HttpFrame(com.firenio.codec.http11.HttpFrame) File(java.io.File)

Aggregations

HttpFrame (com.firenio.codec.http11.HttpFrame)2 HttpStatus (com.firenio.codec.http11.HttpStatus)1 File (java.io.File)1