Examples of BBuffer


Examples of org.apache.tomcat.lite.io.BBuffer

        net.getIn().append(POST);
        net.getIn().close();

        IOBuffer receiveBody = http.receiveBody;
        IOBuffer appData = receiveBody;
        BBuffer res = BBuffer.allocate(1000);
        appData.readAll(res);

        assertEquals(res.toString(), "1234");
        assertFalse(((Http11Connection)http.conn).keepAlive());

        http.sendBody.queue(res);
        http.getOut().close();
        http.startSending();
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

            tr = new ThreadRunner(thr, cnt) {

                public void makeRequest(int i) throws Exception {
                    try {
                        BBuffer out = BBuffer.allocate();
                        String url = ssl ? "https://localhost:8443/hello" :
                            "http://localhost:8802/hello";
                        HttpURLConnection con =
                            TestMain.getUrl(url, out);
                        if (con.getResponseCode() != 200) {
                            errors.incrementAndGet();
                        }
                        if (!"Hello world".equals(out.toString())) {
                            errors.incrementAndGet();
                            System.err.println("bad result " + out);
                        }
                    } catch(Throwable t) {
                        t.printStackTrace();
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

        head.readLine(line);

        int idx = 0;

        BBuffer upgrade = null;

        while(line.remaining() > 0) {
            // not empty..
            idx = msgBytes.addHeader();
            BBuffer nameBuf = msgBytes.getHeaderName(idx);
            BBuffer valBuf = msgBytes.getHeaderValue(idx);
            parseHeader(http, head, line, nameBuf, valBuf);

            // TODO: process 'interesting' headers here.
            if (nameBuf.equalsIgnoreCase("connection")) {
                // TODO: save and remove if not recognized
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

            HttpMessage.HttpMessageBytes msgBytes ) {

        // process each "cookie" header
        for (int i = 0; i < msgBytes.headerCount; i++) {
            if (msgBytes.getHeaderName(i).equalsIgnoreCase("Cookie")) {
                BBuffer bc = msgBytes.getHeaderValue(i);
                if (bc.remaining() == 0) {
                    continue;
                }
                processCookieHeader(cookies, cookiesCache,
                        bc.array(),
                        bc.getOffset(),
                        bc.getLength());

            }

        }
    }
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

                try {
                    SpdyConnection.readShort(iob);

                    HttpMessageBytes resBytes = ch.getResponse().getMsgBytes();

                    BBuffer head = processHeaders(iob, ch, resBytes);
                } catch (Throwable t) {
                    log.log(Level.SEVERE, "Error parsing head", t);
                    abort("Error reading headers " + t);
                    return;
                }
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

            }
        }
        // Wrapper - so we don't change position in head
        headRecvBuf.wrapTo(headW);

        BBuffer nameBuf = BBuffer.wrapper();
        BBuffer valBuf = BBuffer.wrapper();

        for (int i = 0; i < nvCount; i++) {

            int nameLen = SpdyConnection.readShort(headW);
            if (nameLen > headW.remaining()) {
                abort("Name too long");
            }

            nameBuf.setBytes(headW.array(), headW.position(),
                            nameLen);
            headW.advance(nameLen);

            int valueLen = SpdyConnection.readShort(headW);
            valBuf.setBytes(headW.array(), headW.position(),
                            valueLen);
            headW.advance(valueLen);

            // TODO: no need to send version, method if default

            if (nameBuf.equals("method")) {
                valBuf.wrapTo(reqBytes.method());
            } else if (nameBuf.equals("version")) {
                valBuf.wrapTo(reqBytes.protocol());
            } else if (nameBuf.equals("url")) {
                valBuf.wrapTo(reqBytes.url());
                // TODO: spdy uses full URL, we may want to trim
                // also no host header
            } else {
                int idx = reqBytes.addHeader();
                nameBuf.wrapTo(reqBytes.getHeaderName(idx));
                valBuf.wrapTo(reqBytes.getHeaderValue(idx));
            }

            // TODO: repeated values are separated by a 0
        }
        return headW;
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

        if (!checkConnection(http)) {
            return;
        }
        MultiMap mimeHeaders = http.getRequest().getMimeHeaders();

        BBuffer headBuf = BBuffer.allocate();
        SpdyConnection.appendShort(headBuf, mimeHeaders.size() + 3);
        serializeMime(mimeHeaders, headBuf);

        // TODO: url - with host prefix , method
        // optimize...
        SpdyConnection.appendAsciiHead(headBuf, "version");
        SpdyConnection.appendAsciiHead(headBuf, "HTTP/1.1");

        SpdyConnection.appendAsciiHead(headBuf, "method");
        SpdyConnection.appendAsciiHead(headBuf, http.getRequest().getMethod());

        SpdyConnection.appendAsciiHead(headBuf, "url");
        // TODO: url
        SpdyConnection.appendAsciiHead(headBuf, http.getRequest().requestURL());

        if (headerCompression && httpConnector.compression) {
            headerCompressBuffer.recycle();
            headCompressOut.compress(headBuf, headerCompressBuffer, false);
            headBuf.recycle();
            headerCompressBuffer.copyAll(headBuf);
        }

        // Frame head - 8
        BBuffer out = BBuffer.allocate();
        // Syn-reply
        out.putByte(0x80);
        out.putByte(0x01);
        out.putByte(0x00);
        out.putByte(0x01);

        CBuffer method = http.getRequest().method();
        if (method.equals("GET") || method.equals("HEAD")) {
            http.getOut().close();
        }

        if (http.getOut().isAppendClosed()) {
            out.putByte(0x01); // closed
        } else {
            out.putByte(0x00);
        }

        // Length, channel id (4) + unused (2) - headBuf has header count
        // and headers
        SpdyConnection.append24(out, headBuf.remaining() + 6);

        if (serverMode) {
            http.channelId = 2 * lastOutStream.incrementAndGet();
        } else {
            http.channelId = 2 * lastOutStream.incrementAndGet() + 1;
        }
        SpdyConnection.appendInt(out, http.channelId);

        http.setConnection(this);

        synchronized (channels) {
            channels.put(http.channelId, http);
        }

        out.putByte(0x00); // no priority
        out.putByte(0x00);

        sendFrame(out, headBuf);

        if (http.outMessage.state == HttpMessage.State.HEAD) {
            http.outMessage.state = HttpMessage.State.BODY_DATA;
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

        }
        http.getResponse().setCommitted(true);

        MultiMap mimeHeaders = http.getResponse().getMimeHeaders();

        BBuffer headBuf = BBuffer.allocate();


        //mimeHeaders.remove("content-length");
        BBuffer headers = headBuf;
        if (headerCompression) {
            headers = BBuffer.allocate();
        }

        //SpdyConnection.appendInt(headers, http.channelId);
        //headers.putByte(0);
        //headers.putByte(0);
        SpdyConnection.appendShort(headers, mimeHeaders.size() + 2);

        // chrome will crash if we don't send the header
        serializeMime(mimeHeaders, headers);

        // Must be at the end
        SpdyConnection.appendAsciiHead(headers, "status");
        SpdyConnection.appendAsciiHead(headers,
                Integer.toString(http.getResponse().getStatus()));

        SpdyConnection.appendAsciiHead(headers, "version");
        SpdyConnection.appendAsciiHead(headers, "HTTP/1.1");

        if (headerCompression) {
            headerCompressBuffer.recycle();
            headCompressOut.compress(headers, headerCompressBuffer, false);
            headerCompressBuffer.copyAll(headBuf);
            headerCompressBuffer.recycle();
        }

        BBuffer frameHead = BBuffer.allocate();
        // Syn-reply
        frameHead.putByte(0x80); // Control
        frameHead.putByte(0x01); // version
        frameHead.putByte(0x00); // 00 02 - SYN_REPLY
        frameHead.putByte(0x02);

        // It seems piggibacking data is not allowed
        frameHead.putByte(0x00);

        int len = headBuf.remaining() + 6;
        SpdyConnection.append24(frameHead, len);

//        // Stream-Id, unused
        SpdyConnection.appendInt(frameHead, http.channelId);
        frameHead.putByte(0);
        frameHead.putByte(0);

        sendFrame(frameHead, headBuf);
    }
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

            // Default is what the socket tells us. Overriden if a host is
            // found/parsed
            return true;
        }

        BBuffer valueBC = hostHF.valueB;
        if (valueBC == null) {
            valueBC = BBuffer.allocate();
            hostHF.getValue().toAscii(valueBC);
        }
        byte[] valueB = valueBC.array();
        int valueL = valueBC.getLength();
        int valueS = valueBC.getStart();

        int colonPos = valueBC.indexOf(':', 0);

        serverNameMB.recycle();

        boolean ipv6 = (valueB[valueS] == '[');
        boolean bracketClosed = false;
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBuffer

    /**
     * Server mode, request just received.
     */
    protected void processReceivedHeaders() throws IOException {
        BBuffer url = getMsgBytes().url();
        if (url.remaining() == 0) {
            System.err.println("No input");
        }
        if (url.get(0) == 'h') {
            int firstSlash = url.indexOf('/', 0);
            schemeMB.appendAscii(url.array(),
                    url.getStart(), firstSlash + 2);
            if (!schemeMB.equals("http://") &&
                    !schemeMB.equals("https://")) {
                httpCh.getResponse().setStatus(400);
                httpCh.abort("Error normalizing url " +
                        getMsgBytes().url());
                return;
            }

            int urlStart = url.indexOf('/', firstSlash + 2);
            serverNameMB.recycle();
            serverNameMB.appendAscii(url.array(),
                    url.getStart() + firstSlash + 2, urlStart - firstSlash - 2);

            url.position(url.getStart() + urlStart);
        }
        if (!httpCh.normalize(getMsgBytes().url())) {
            httpCh.getResponse().setStatus(400);
            httpCh.abort("Error normalizing url " +
                    getMsgBytes().url());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.