Examples of DataChunk


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

            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

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

            }
           
            // 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

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

        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

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

        private void parseContentTypeHeader() {
            contentTypeParsed = true;
           
            if (!contentType.isSet()) {
                final DataChunk dc = headers.getValue(Header.ContentType);
               
                if (dc != null && !dc.isNull()) {
                    setContentType(dc.toString());
                }
            }
        }
View Full Code Here

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

        private void parseContentTypeHeader() {
            contentTypeParsed = true;
           
            if (!contentType.isSet()) {
                final DataChunk dc = headers.getValue(Header.ContentType);
               
                if (dc != null && !dc.isNull()) {
                    setContentType(dc.toString());
                }
            }
        }
View Full Code Here

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

     * data.
     */
    public boolean checkUserAgent(final HttpRequestPacket request) {
        // Check for incompatible Browser
        if (!noCompressionUserAgents.isEmpty()) {
            final DataChunk userAgentValueDC =
                    request.getHeaders().getValue(Header.UserAgent);
            if (userAgentValueDC != null
                    && indexOf(noCompressionUserAgents.getArray(),
                    userAgentValueDC) != -1) {
                return false;
View Full Code Here

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

    }
   
    private static boolean isClientSupportContentEncoding(
            HttpRequestPacket request, final String[] aliases) {
        // Check if browser support gzip encoding
        final DataChunk acceptEncodingDC =
                request.getHeaders().getValue(Header.AcceptEncoding);
        if (acceptEncodingDC == null) {
            return false;
        }
        String alias = null;
        int idx = -1;
        for (int i = 0, len = aliases.length; i < len; i++) {
            alias = aliases[i];
            idx = acceptEncodingDC.indexOf(alias, 0);
            if (idx != -1) {
                break;
            }
        }

        if (idx == -1) {
            return false;
        }

        assert alias != null;
       
        // we only care about q=0/q=0.0.  If present, the user-agent
        // doesn't support this particular compression.
        int qvalueStart = acceptEncodingDC.indexOf(';', idx + alias.length());
        if (qvalueStart != -1) {
            qvalueStart = acceptEncodingDC.indexOf('=', qvalueStart);
            final int commaIdx = acceptEncodingDC.indexOf(',', qvalueStart);
            final int qvalueEnd = commaIdx != -1 ? commaIdx : acceptEncodingDC.getLength();
            if (HttpUtils.convertQValueToFloat(acceptEncodingDC,
                    qvalueStart + 1,
                    qvalueEnd) == 0.0f) {
                return false;
            }
View Full Code Here

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

            return false;
        }

        final MimeHeaders responseHeaders = response.getHeaders();
        // Check if content is already encoded (no matter which encoding)
        final DataChunk contentEncodingMB =
                responseHeaders.getValue(Header.ContentEncoding);
        if (contentEncodingMB != null && !contentEncodingMB.isNull()) {
            return false;
        }

        if (!CompressionConfig.isClientSupportCompression(compressionConfig,
                response.getRequest(), aliases)) {
View Full Code Here

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

                                              final byte[] tempEncodingBuffer) {
        final int mimeHeadersNum = mimeHeaders.size();

        for (int i = 0; i < mimeHeadersNum; i++) {
            if (!mimeHeaders.setSerialized(i, true)) {
                final DataChunk value = mimeHeaders.getValue(i);
                if (!value.isNull()) {
                    buffer = encodeMimeHeader(memoryManager,
                                              buffer,
                                              mimeHeaders.getName(i),
                                              value,
                                              tempEncodingBuffer,
View Full Code Here

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

        if (!httpHeader.getUpgradeDC().isNull()) {
            // If it's upgraded Http connection - ignore the content encoding
            return;
        }
       
        final DataChunk bc =
                httpHeader.getHeaders().getValue(Header.ContentEncoding);
       
        if (bc != null) {
            final List<ContentEncoding> encodings = httpHeader.getContentEncodings(true);
            int currentIdx = 0;

            int commaIdx;
            do {
                commaIdx = bc.indexOf(',', currentIdx);
                final ContentEncoding ce = lookupContentEncoding(bc, currentIdx,
                        commaIdx >= 0 ? commaIdx : bc.getLength());
                if (ce != null && ce.wantDecode(httpHeader)) {
                    encodings.add(0, ce);
                } else {
                    // if encoding was not found or doesn't want to decode -
                    // following could not be applied
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.