Package org.glassfish.grizzly.http.util

Examples of org.glassfish.grizzly.http.util.DataChunk


        if (semicolonPos == 0) {
            semicolonPos = decodedURI.indexOf(';', 0);
        }

        DataChunk localDecodedURI = decodedURI;
        if (semicolonPos >= 0) {
            charChunk.setEnd(semicolonPos);
            // duplicate the URI path, because Mapper may corrupt the attributes,
            // which follow the path
            localDecodedURI = mappingData.tmpMapperDC;
            localDecodedURI.duplicate(decodedURI);
        }


        map(requestPacket, localDecodedURI, mappingData);
        charChunk.setEnd(oldEnd);
View Full Code Here


        if (semicolonPos == 0) {
            semicolonPos = decodedURI.indexOf(';', 0);
        }

        DataChunk localDecodedURI = decodedURI;
        if (semicolonPos >= 0) {
            charChunk.setEnd(semicolonPos);
            // duplicate the URI path, because Mapper may corrupt the attributes,
            // which follow the path
            localDecodedURI = mappingData.tmpMapperDC;
            localDecodedURI.duplicate(decodedURI);
        }


        map(serverName, localDecodedURI, mappingData);
        charChunk.setEnd(oldEnd);
View Full Code Here

    public void map(final HttpRequestPacket requestPacket, final DataChunk uri,
                    final MappingData mappingData) throws Exception {

        final CharChunk hostCC;
        if (hosts.length > 1) {
            final DataChunk host = requestPacket.serverName();
            if (host.isNull()) {
                host.getCharChunk().append(defaultHostName);
            } else if (host.getLength() == 0) {
                throw new Exception("Host is not set");
            } else {
                host.toChars(Constants.DEFAULT_HTTP_CHARSET);
            }
           
            hostCC = host.getCharChunk();
        } else {
            hostCC = null;
        }
       
        uri.toChars(Charsets.UTF8_CHARSET);
View Full Code Here

            // no more cookie headers headers
            if (pos < 0) {
                break;
            }

            DataChunk cookieValue = headers.getValue(pos);
            if (cookieValue == null || cookieValue.isNull()) {
                pos++;
                continue;
            }

            // Uncomment to test the new parsing code
            if (cookieValue.getType() == DataChunk.Type.Bytes) {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing b[]: " + cookieValue.toString());
                }

                final ByteChunk byteChunk = cookieValue.getByteChunk();
                CookieParserUtils.parseClientCookies(this, byteChunk.getBuffer(),
                        byteChunk.getStart(),
                        byteChunk.getLength());
            } else if (cookieValue.getType() == DataChunk.Type.Buffer) {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing buffer: " + cookieValue.toString());
                }

                final BufferChunk bufferChunk = cookieValue.getBufferChunk();
                CookieParserUtils.parseClientCookies(this, bufferChunk.getBuffer(),
                        bufferChunk.getStart(),
                        bufferChunk.getLength());
            } else {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing string: " + cookieValue.toString());
                }

                final String value = cookieValue.toString();
                CookieParserUtils.parseClientCookies(this, value,
                        CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE,
                        CookieUtils.RFC_6265_SUPPORT_ENABLED);
            }
View Full Code Here

            // no more cookie headers headers
            if (pos < 0) {
                break;
            }

            DataChunk cookieValue = headers.getValue(pos);
            if (cookieValue == null || cookieValue.isNull()) {
                pos++;
                continue;
            }

            // Uncomment to test the new parsing code
            if (cookieValue.getType() == DataChunk.Type.Bytes) {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing b[]: " + cookieValue.toString());
                }

                final ByteChunk byteChunk = cookieValue.getByteChunk();
                CookieParserUtils.parseServerCookies(this, byteChunk.getBuffer(),
                        byteChunk.getStart(),
                        byteChunk.getLength(),
                        CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE,
                        CookieUtils.RFC_6265_SUPPORT_ENABLED);
            } else if (cookieValue.getType() == DataChunk.Type.Buffer) {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing b[]: " + cookieValue.toString());
                }

                final BufferChunk bufferChunk = cookieValue.getBufferChunk();
                CookieParserUtils.parseServerCookies(this, bufferChunk.getBuffer(),
                        bufferChunk.getStart(),
                        bufferChunk.getLength(),
                        CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE,
                        CookieUtils.RFC_6265_SUPPORT_ENABLED);
            } else {
                if (logger.isLoggable(Level.FINE)) {
                    log("Parsing string: " + cookieValue.toString());
                }

                final String value = cookieValue.toString();
                CookieParserUtils.parseServerCookies(this, value,
                        CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE,
                        CookieUtils.RFC_6265_SUPPORT_ENABLED);
            }
View Full Code Here

        inputBuffer.initialize(this, ctx);
       
        parameters.setHeaders(request.getHeaders());
        parameters.setQuery(request.getQueryStringDC());

        final DataChunk remoteUser = request.remoteUser();
        if (!remoteUser.isNull()) {
            setUserPrincipal(new GrizzlyPrincipal(remoteUser.toString()));
        }

        if (httpServerFilter != null) {
            final ServerFilterConfiguration configuration =
                    httpServerFilter.getConfiguration();
View Full Code Here

     */
    protected void parseSessionId() {
        if (sessionParsed) return;

        sessionParsed = true;
        final DataChunk uriDC = request.getRequestURIRef().getRequestURIBC();
       
        final boolean isUpdated;
       
        switch (uriDC.getType()) {
            case Bytes:
                isUpdated = parseSessionId(uriDC.getByteChunk());
                break;
            case Buffer:
                isUpdated = parseSessionId(uriDC.getBufferChunk());
                break;
            case Chars:
                isUpdated = parseSessionId(uriDC.getCharChunk());
                break;
            default:
                throw new IllegalStateException("Unexpected DataChunk type: " + uriDC.getType());
        }
       
        if (isUpdated) {
            uriDC.notifyDirectUpdate();
        }
    }
View Full Code Here

            return;
        }
       
        final MimeHeaders headers = request.getHeaders();
       
        DataChunk hostDC = null;
       
        // Check for a full URI (including protocol://host:port/)
       
        final DataChunk uriBC = request.getRequestURIRef().getRequestURIBC();
       
        if (uriBC.startsWithIgnoreCase("http", 0)) {

            int pos = uriBC.indexOf("://", 4);
            int uriBCStart = uriBC.getStart();
            int slashPos;
            if (pos != -1) {
//                final Buffer uriB = uriBC.getBuffer();
                slashPos = uriBC.indexOf('/', pos + 3);
                if (slashPos == -1) {
                    slashPos = uriBC.getLength();
                    // Set URI as "/"
                    uriBC.setStart(uriBCStart + pos + 1);
                    uriBC.setEnd(uriBCStart + pos + 2);
                } else {
                    uriBC.setStart(uriBCStart + slashPos);
                    uriBC.setEnd(uriBC.getEnd());
                }
                hostDC = headers.setValue(Header.Host);
                hostDC.set(uriBC, uriBCStart + pos + 3, uriBCStart + slashPos);
            }

        }

        // --------------------------

        if (hostDC == null) {
            hostDC = headers.getValue(Header.Host);
        }

        final boolean isHttp11 = protocol == Protocol.HTTP_1_1;
       
        // Check host header
        if (isHttp11 && (hostDC == null || hostDC.isNull())) {
            state.error = true;
            return;
        }
        request.unparsedHostC = hostDC;
       
        // If it's upgraded HTTP - don't check semantics
        if (isUpgraded) {
            return;
        }

        final Method method = request.getMethod();
       
        final PayloadExpectation payloadExpectation = method.getPayloadExpectation();
        if (payloadExpectation != PayloadExpectation.NOT_ALLOWED) {
            final boolean hasPayload =
                    request.getContentLength() > 0 || request.isChunked();
           
            if (hasPayload && payloadExpectation == PayloadExpectation.UNDEFINED &&
                    !allowPayloadForUndefinedHttpMethods) {
                // if payload is not allowed for the "undefined" methods
                state.error = true;
                // Send 400; Bad Request
                HttpStatus.BAD_REQUEST_400.setValues(response);
                return;
            }
           
            request.setExpectContent(hasPayload);
        } else {
            request.setExpectContent(method == Method.CONNECT);
        }
       
        // ------ Set keep-alive flag
        if (method == Method.CONNECT) {
            state.keepAlive = false;
        } else {
            final DataChunk connectionValueDC = headers.getValue(Header.Connection);
            final boolean isConnectionClose = (connectionValueDC != null &&
                    connectionValueDC.equalsIgnoreCaseLowerCase(CLOSE_BYTES));

            if (!isConnectionClose) {
                state.keepAlive = allowKeepAlive && (isHttp11 ||
                        (connectionValueDC != null &&
                        connectionValueDC.equalsIgnoreCaseLowerCase(KEEPALIVE_BYTES)));
            }
        }
       
        if (request.requiresAcknowledgement()) {
            // if we have any request content, we can ignore the Expect
View Full Code Here

            }
           
            // Optimize content-type serialization depending on its state
            final ContentType contentType = response.getContentTypeHolder();
            if (contentType.isMimeTypeSet()) {
                final DataChunk contentTypeValue = headers.setValue(Header.ContentType);
                if (contentTypeValue.isNull()) {
                    contentType.serializeToDataChunk(contentTypeValue);
                }
            } else if (defaultResponseContentType != null) {
                final DataChunk contenTypeValue = headers.setValue(Header.ContentType);
                if (contenTypeValue.isNull()) {
                    final String ce = response.getCharacterEncoding();
                    if (ce == null) {
                        contenTypeValue.setBytes(defaultResponseContentTypeBytes);
                    } else {
                        final byte[] array = ContentType.compose(
                                defaultResponseContentTypeBytesNoCharset, ce);
                        contenTypeValue.setBytes(array);
                    }
                }
            }
        }
View Full Code Here

        output = put(memoryManager, output, Constants.SP);
        output = put(memoryManager, output, httpResponse.getHttpStatus().getStatusBytes());
        output = put(memoryManager, output, Constants.SP);
        if (httpResponse.isCustomReasonPhraseSet()) {
           
            final DataChunk customReasonPhrase =
                    httpResponse.isHtmlEncodingCustomReasonPhrase() ?
                    HttpStatus.filter(httpResponse.getReasonPhraseDC()) :
                    HttpStatus.filterNonPrintableCharacters(httpResponse.getReasonPhraseDC());
           
            output = put(memoryManager, output,
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.http.util.DataChunk

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.