Package org.glassfish.grizzly.http.util

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


            onInitialLineEncoded(httpHeader, ctx);

            encodedBuffer = encodeKnownHeaders(memoryManager, encodedBuffer,
                    httpHeader);

            final MimeHeaders mimeHeaders = httpHeader.getHeaders();
            final byte[] tempEncodingBuffer = httpHeader.getTempHeaderEncodingBuffer();
            encodedBuffer = encodeMimeHeaders(memoryManager, encodedBuffer, mimeHeaders, tempEncodingBuffer);
            onHttpHeadersEncoded(httpHeader, ctx);
            encodedBuffer = put(memoryManager, encodedBuffer, CRLF_BYTES);
            encodedBuffer.trim();
View Full Code Here


                        LAST_CHUNK_CRLF_BYTES);
            }

            if (isTrailer) {
                final HttpTrailer httpTrailer = (HttpTrailer) httpContent;
                final MimeHeaders mimeHeaders = httpTrailer.getHeaders();
                httpChunkTrailer = HttpCodecFilter.encodeMimeHeaders(memoryManager,
                        httpChunkTrailer, mimeHeaders, httpContent.getHttpHeader().getTempHeaderEncodingBuffer());
            }

        }
View Full Code Here

                        LAST_CHUNK_CRLF_BYTES);
            }

            if (isTrailer) {
                final HttpTrailer httpTrailer = (HttpTrailer) httpContent;
                final MimeHeaders mimeHeaders = httpTrailer.getHeaders();
                httpChunkTrailer = HttpCodecFilter.encodeMimeHeaders(memoryManager,
                        httpChunkTrailer, mimeHeaders, httpContent.getHttpHeader().getTempHeaderEncodingBuffer());
            }

        }
View Full Code Here

    private static void checkHttpTrailer(final HttpContent httpContent) {
        if (HttpTrailer.isTrailer(httpContent)) {
            final HttpTrailer httpTrailer = (HttpTrailer) httpContent;
            final HttpHeader httpHeader = httpContent.getHttpHeader();
           
            final MimeHeaders trailerHeaders = httpTrailer.getHeaders();
            final int size = trailerHeaders.size();
            for (int i = 0; i < size; i++) {
                httpHeader.addHeader(
                        trailerHeaders.getName(i).toString(),
                        trailerHeaders.getValue(i).toString());
            }
        }
    }   
View Full Code Here

        if (request.getHeaderParsingState().contentLengthsDiffer) {
            request.getProcessingState().error = true;
            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) {
            request.setExpectContent(
                    request.getContentLength() != -1 || request.isChunked());
        } 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 = isHttp11 ||
View Full Code Here

            response.setContentEncodingsSelected(true);
            response.setContentLength(-1);
            response.setChunked(false);
        }

        final MimeHeaders headers = response.getHeaders();
       
        if (!entityBody) {
            response.setContentLength(-1);
        } else {
            String contentLanguage = response.getContentLanguage();
            if (contentLanguage != null) {
                headers.setValue(Header.ContentLanguage).setString(contentLanguage);
            }
           
            // 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);
                    }
                }
            }
        }

        if (!response.containsHeader(Header.Date)) {
            response.getHeaders().addValue(Header.Date)
                    .setBytes(FastHttpDateFormat.getCurrentDateBytes());
        }

        final ProcessingState state = response.getProcessingState();

        if (entityBody && !isHttp11 && response.getContentLength() == -1) {
            // HTTP 1.0 response with no content-length having been set.
            // Close the connection to signal the response as being complete.
            state.keepAlive = false;
        } else if (entityBody && !response.isChunked() && response.getContentLength() == -1) {
            // HTTP 1.1 response with chunking disabled and no content-length having been set.
            // Close the connection to signal the response as being complete.
            state.keepAlive = false;
        } else if (!checkKeepAliveRequestsCount(ctx)) {
            // We processed max allowed HTTP requests over the keep alive connection
            state.keepAlive = false;
        }
       
        // If we know that the request is bad this early, add the
        // Connection: close header.
        state.keepAlive = (state.keepAlive &&
                !statusDropsConnection(response.getStatus()));

        if (!state.keepAlive) {
            headers.setValue(Header.Connection).setBytes(CLOSE_BYTES);
        } else if (!isHttp11 && !state.error) {
            headers.setValue(Header.Connection).setBytes(KEEPALIVE_BYTES);
        }

        return encodedHttpContent;
    }       
View Full Code Here

            key.recycle();
            return CacheResult.FAILED_CACHE_FULL;
        }

        final HttpResponsePacket response = request.getResponse();
        final MimeHeaders headers = response.getHeaders();
       
        final String contentType = response.getContentType();
       
        final FileCacheEntry entry;
        if (cacheFile != null) { // If we have a file - try to create File-aware cache resource
            entry = createEntry(cacheFile);
            entry.setCanBeCompressed(canBeCompressed(cacheFile, contentType));
        } else {
            entry = new FileCacheEntry(this);
            entry.type = CacheType.TIMESTAMP;
        }

        entry.key = key;
        entry.requestURI = requestURI;

        entry.lastModified = lastModified;
        entry.contentType = ContentType.newContentType(contentType);
        entry.xPoweredBy = headers.getHeader(Header.XPoweredBy);
        entry.date = headers.getHeader(Header.Date);
        entry.lastModifiedHeader = headers.getHeader(Header.LastModified);
        entry.host = host;
        entry.Etag = headers.getHeader(Header.ETag);
        entry.server = headers.getHeader(Header.Server);

        fileCacheMap.put(key, entry);
       
        notifyProbesEntryAdded(this, entry);
       
View Full Code Here

     * Return an array of all the header names set for this response, or
     * a zero-length array if no headers have been set.
     */
    public String[] getHeaderNames() {
        checkResponse();
        MimeHeaders headers = response.getHeaders();
        int n = headers.size();
        String[] result = new String[n];
        for (int i = 0; i < n; i++) {
            result[i] = headers.getName(i).toString();
        }
        return result;

    }
View Full Code Here

        }
       
        final String cookieString = sb.toString();
       
        boolean set = false;
        MimeHeaders headers = response.getHeaders();
        int n = headers.size();
        for (int i = 0; i < n; i++) {
            if (headers.getName(i).toString().equals(headername)) {
                if (headers.getValue(i).toString().startsWith(startsWith)) {
                    headers.getValue(i).setString(cookieString);
                    set = true;
                }
            }
        }
        if (!set) {
View Full Code Here

     * Is chunking allowed to be used or not.
     */
    private boolean chunkingAllowed;

    public HttpHeader() {
        this(new MimeHeaders());
    }
View Full Code Here

TOP

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

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.