Package kilim.http

Examples of kilim.http.HttpRequest


        @Override
        public void execute() throws Pausable, Exception {
            try {
                // We will reuse the req and resp objects
                HttpRequest req = new HttpRequest();
                HttpResponse resp = new HttpResponse();
                while (true) {
                    super.readRequest(req);
                    System.out.println("Received: " + req);
                    if (req.method.equals("GET") || req.method.equals("HEAD")) {
                        resp.setContentType("text/html");
                        PrintWriter pw = new PrintWriter(resp.getOutputStream());
                        // Note that resp.getOutputStream() does not write to the socket; it merely buffers the entire
                        // output.
                        pw.append("<html><body>path = ");
                        pw.append(req.uriPath).append("<p>");
                        KeyValues kvs = req.getQueryComponents();
                        for (int i = 0; i < kvs.count; i++) {
                            pw.append(kvs.keys[i]).append(" = ").append(kvs.values[i]).append("<br>");
                        }
                        pw.append("</body></html>");
                        pw.flush();
                        sendResponse(resp);
                    } else {
                        super.problem(resp, HttpResponse.ST_FORBIDDEN, "Only GET and HEAD accepted");
                    }
                   
                    if (!req.keepAlive())
                        break;
                    break;
                }
            } catch (EOFException e) {
                System.out.println("[" + this.id + "] Connection Terminated");
View Full Code Here


   
    public static class TestHttpServer extends HttpSession {
        public void execute() throws Pausable, Exception {
            try {
                while (true) {
                    HttpRequest req = new HttpRequest();
                    HttpResponse resp = new HttpResponse();
                    // Fill up the request object. This pauses until the entire request has
                    // been read in, including all chunks.
                    super.readRequest(req);
                    // System.out.println(req);
                    if (req.method.equals("GET")) {
                        resp.setContentType("text");
                        PrintWriter pw = new PrintWriter(resp.getOutputStream());
                        pw.append(req.uriPath).append(req.getQueryComponents().toString());
                        pw.flush();
                        sendResponse(resp);
                    } else if (req.method.equals("POST")) {
                        resp.setContentType("text");
                        PrintWriter pw = new PrintWriter(resp.getOutputStream());
                        String s = req.extractRange(req.contentOffset, req.contentOffset + req.contentLength);
                        pw.append(s);
                        pw.flush();
                        sendResponse(resp);
                    } else {
                        problem(resp, HttpResponse.ST_BAD_REQUEST, "Only get accepted");
                    }
                    if (!req.keepAlive()) {
                        break;
                    }
                }
            } catch (EOFException ignore) {
            }
View Full Code Here

    @Override
    public void execute() throws Pausable, Exception {
        try {
            // We will reuse the req and resp objects
            HttpRequest req = new HttpRequest();
            HttpResponse resp = new HttpResponse();
            while (true) {
                // Fill up the request object. This pauses until the entire request has
                // been read in, including all chunks.
                super.readRequest(req);
                // System.out.println(req);
                if (req.method.equals("GET") || req.method.equals("HEAD")) {
                    File f = urlToPath(req);
                    System.out.println("[" + this.id + "] Read: " + f.getPath());
                    if (check(resp, f)) {
                        boolean headOnly = req.method.equals("HEAD");
                        if (f.isDirectory())
                            sendDirectory(resp, f, headOnly);
                        else
                            sendFile(resp, f, headOnly);
                    }
                } else {
                    super.problem(resp, HttpResponse.ST_FORBIDDEN, "Only GET and HEAD accepted");
                }
                if (!req.keepAlive()) {
                    break;
                }
            }
        } catch (EOFException e) {
            System.out.println("[" + this.id + "] Connection Terminated");
View Full Code Here

TOP

Related Classes of kilim.http.HttpRequest

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.