Package org.glassfish.grizzly.http.util

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


        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

     * 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

    }
   
    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

            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

                                              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

        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

        httpHeader.setContentEncodingsSelected(true);
       
        final ContentEncoding[] encodingsLibrary = contentEncodings.getArray();
        if (encodingsLibrary == null) return;

        final DataChunk bc =
                httpHeader.getHeaders().getValue(Header.ContentEncoding);
       
        final boolean isSomeEncodingApplied = bc != null && bc.getLength() > 0;
        if (isSomeEncodingApplied && bc.equals("identity")) {
            // remove the header as it's illegal to include the content-encoding
            // header with a value of identity.  Since the value is identity,
            // return without applying any transformation.
            httpHeader.getHeaders().removeHeader(Header.ContentEncoding);
            return;
View Full Code Here

                    return new HttpHandlerCallable(httpHandler,
                            request, response);
                }
            }

            final DataChunk decodedURI = request.getRequest()
                    .getRequestURIRef().getDecodedRequestURIBC(isAllowEncodedSlash());

            mappingData = request.getNote(MAPPING_DATA);
            if (mappingData == null) {
                mappingData = new MappingData();
                request.setNote(MAPPING_DATA, mappingData);
            } else {
                mappingData.recycle();
            }
            HttpHandler httpHandler;

            final CharChunk decodedURICC = decodedURI.getCharChunk();
            final int semicolon = decodedURICC.indexOf(';', 0);

            // Map the request without any trailling.
            httpHandler = mapUriWithSemicolon(request, decodedURI,
                    semicolon, mappingData);
            if (httpHandler == null || httpHandler instanceof ContainerMapper) {
                String ext = decodedURI.toString();
                String type = "";
                if (ext.lastIndexOf(".") > 0) {
                    ext = "*" + ext.substring(ext.lastIndexOf("."));
                    type = ext.substring(ext.lastIndexOf(".") + 1);
                }

                if (!MimeType.contains(type) && !"/".equals(ext)) {
                    initializeFileURLPattern(ext);
                    mappingData.recycle();
                    httpHandler = mapUriWithSemicolon(request, decodedURI,
                            semicolon, mappingData);
                } else {
//                    super.service(request, response);
//                    return;
                    return new SuperCallable(request, response);
                }
            }

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, "Request: {0} was mapped to Adapter: {1}",
                        new Object[]{decodedURI.toString(), httpHandler});
            }

            // The Adapter used for servicing static pages doesn't decode the
            // request by default, hence do not pass the undecoded request.
            if (httpHandler == null || httpHandler instanceof ContainerMapper) {
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 = req.getNote(DATA_CHUNK);
                if (localDecodedURI == null) {
                    localDecodedURI = DataChunk.newInstance();
                    req.setNote(DATA_CHUNK, localDecodedURI);
                }
                localDecodedURI.duplicate(decodedURI);
            }


            try {
                return map(req, localDecodedURI, mappingData);
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.