Package org.glassfish.grizzly.http.util

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


            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(state.getHttpContext())) {
            // 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


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

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

         * @param value the mime header value.
         */
        @SuppressWarnings({"unchecked"})
        public final T header(String name, String value) {
            if (mimeHeaders == null) {
                mimeHeaders = new MimeHeaders();
            }
            mimeHeaders.addValue(name).setString(value);
            handleSpecialHeaderAdd(name, value);
            return (T) this;
        }
View Full Code Here

         * @param value the mime header value.
         */
        @SuppressWarnings({"unchecked"})
        public final T header(Header header, String value) {
            if (mimeHeaders == null) {
                mimeHeaders = new MimeHeaders();
            }
            mimeHeaders.addValue(header).setString(value);
            handleSpecialHeaderAdd(header.toString(), value);

            return (T) this;
View Full Code Here

         * Sets the maximum number of headers allowed.
         */
        @SuppressWarnings({"unchecked"})
        public final T maxNumHeaders(int maxHeaders) {
            if (mimeHeaders == null) {
                mimeHeaders = new MimeHeaders();
            }
            mimeHeaders.setMaxNumHeaders(maxHeaders);
            return (T) this;
        }
View Full Code Here

                .append("\n  reason=").append(getReasonPhrase())
                .append("\n  protocol=").append(getProtocol().getProtocolString())
                .append("\n  content-length=").append(getContentLength())
                .append("\n  committed=").append(isCommitted())
                .append("\n  headers=[");
        final MimeHeaders headersLocal = getHeaders();
        for (final String name : headersLocal.names()) {
            sb.append("\n      ").append(name).append('=')
                    .append(headersLocal.getHeader(name));
        }
        sb.append("]\n)");
       
        return sb.toString();
    }
View Full Code Here

    private MimeHeaders headers;


    protected HttpTrailer(HttpHeader httpHeader) {
        super(httpHeader);
        headers = new MimeHeaders();
    }
View Full Code Here

         * @param name the mime header name.
         * @param value the mime header value.
         */
        public final Builder header(String name, String value) {
            if (mimeHeaders == null) {
                mimeHeaders = new MimeHeaders();
            }
            mimeHeaders.addValue(name).setString(value);
            return this;
        }
View Full Code Here

                .append("\n   url=").append(getRequestURI())
                .append("\n   query=").append(getQueryString())
                .append("\n   protocol=").append(getProtocol().getProtocolString())
                .append("\n   content-length=").append(getContentLength())
                .append("\n   headers=[");
        final MimeHeaders headersLocal = getHeaders();
        for (final String name : headersLocal.names()) {
            sb.append("\n      ").append(name).append('=')
                    .append(headersLocal.getHeader(name));
        }
        sb.append("]\n)");

        return sb.toString();
    }
View Full Code Here

        // skip this one
        if (!response.getContentEncodings().isEmpty()) {
            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,
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.