Package net.sf.cindy.example.http

Examples of net.sf.cindy.example.http.HttpResponse


        boolean keepAlive = "keep-alive".equalsIgnoreCase(request
                .getParam("Connection"));
        ByteBuffer content = getContent(request.getRequestURI());

        HttpResponse response = new HttpResponse();
        response.setVersion(request.getVersion());
        if (content == null) {
            response.setStatusCode(404);
            response.setReasonPhrase("Not Found");
            response.setParam("Content-Type", "text/plain");
            response.setParam("Content-Length", String
                    .valueOf(NOT_FOUND.length));
            response.setContent(NOT_FOUND);
        } else {
            response.setStatusCode(200);
            response.setReasonPhrase("OK");
            response.setParam("Content-Type", mimeMap.getContentTypeFor(request
                    .getRequestURI()));
            response.setParam("Content-Length", String.valueOf(content
                    .remaining()));
        }
        response.setParam("Server", "Cindy Http Server");
        response.setParam("Connection", keepAlive ? "keep-alive" : "close");

        Future future = session.send(response); // send http header
        if (content != null)
            future = session.flush(new DefaultPacket(content)); // send content
        if (!keepAlive)
View Full Code Here


        byte[] header = Charset.UTF8.encodeToArray(request.toString());
        boolean keepAlive = "keep-alive".equalsIgnoreCase(request
                .getParam("Connection"));

        HttpResponse response = new HttpResponse();
        response.setStatusCode(200);
        response.setVersion(request.getVersion());
        response.setReasonPhrase("OK");
        response.setParam("Server", "Cindy Http Server");
        response.setParam("Content-Type", "text/plain");
        response.setParam("Content-Length", String.valueOf(header.length));
        response.setParam("Connection", keepAlive ? "keep-alive" : "close");
        response.setContent(header);

        Future future = session.send(response);
        if (!keepAlive)
            future.addListener(new FutureListener() {
View Full Code Here

TOP

Related Classes of net.sf.cindy.example.http.HttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.