Ejemplo n.º 1
0
        public void SendHeaders(HttpResponseBase response, ResponseCompressionType compressionType, IEntity entity)
        {
            //Data must be in uncompressed format when responding partially
            if (entity.CompressionType != ResponseCompressionType.None)
            {
                //TODO: perhaps we could uncompress object, but for now we don't worry about it
                throw new Exception("Cannot do a partial response on compressed data");
            }

            HttpResponseHeaderHelper.SetContentEncoding(response, compressionType);

            switch (compressionType)
            {
            case ResponseCompressionType.None:
                var contentLength = Range.EndRange - Range.StartRange + 1;
                HttpResponseHeaderHelper.AppendHeader(response, HttpHeaderContentLength, contentLength.ToString());
                break;

            case ResponseCompressionType.GZip:
                response.BufferOutput = true;
                response.Filter       = new GZipStream(response.Filter, CompressionMode.Compress);
                //This means that the output stream will be chunked, so we don't have to worry about content length
                break;

            case ResponseCompressionType.Deflate:
                response.BufferOutput = true;
                response.Filter       = new DeflateStream(response.Filter, CompressionMode.Compress);
                //This means that the output stream will be chunked, so we don't have to worry about content length
                break;
            }

            response.ContentType = entity.ContentType;
            HttpResponseHeaderHelper.AppendHeader(response, HttpHeaderContentRange, Bytes + " " + Range.StartRange + "-" + Range.EndRange + "/" + entity.ContentLength);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends headers required to send an entity.
        /// </summary>
        /// <param name="response">An HTTP response.</param>
        /// <param name="compressionType">The compression type that request wants it sent back in.</param>
        /// <param name="entity"></param>
        public void SendHeaders(HttpResponseBase response, ResponseCompressionType compressionType, IEntity entity)
        {
            if (!(entity.CompressionType == ResponseCompressionType.None || entity.CompressionType == compressionType))
            {
                throw new NotImplementedException("Need to decode in memory, and then stream it");
            }

            HttpResponseHeaderHelper.SetContentEncoding(response, compressionType);

            //How should data be compressed
            if (entity.CompressionType == compressionType)
            {
                //We have the entity stored in the correct compression format so just stream it
                HttpResponseHeaderHelper.AppendHeader(response, HttpHeaderContentLength, entity.ContentLength.ToString());
            }
            else if (entity.CompressionType == ResponseCompressionType.None)
            {
                switch (compressionType)
                {
                case ResponseCompressionType.GZip:
                    response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                    //This means that the output stream will be chunked, so we don't have to worry about content length
                    break;

                case ResponseCompressionType.Deflate:
                    response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                    //This means that the output stream will be chunked, so we don't have to worry about content length
                    break;
                }
            }

            response.ContentType = entity.ContentType;
        }
Ejemplo n.º 3
0
        public void SendHeaders(HttpResponseBase response, ResponseCompressionType compressionType, IEntity entity)
        {
            //Data must be in uncompressed format when responding partially
            if (entity.CompressionType != ResponseCompressionType.None)
            {
                //TODO: perhaps we could uncompress object, but for now we don't worry about it
                throw new Exception("Cannot do a partial response on compressed data");
            }

            HttpResponseHeaderHelper.SetContentEncoding(response, compressionType);

            switch (compressionType)
            {
            case ResponseCompressionType.None:
                var partialContentLength = GetMultipartPartialRequestLength(Ranges, entity.ContentType, entity.ContentLength);
                HttpResponseHeaderHelper.AppendHeader(response, HTTP_HEADER_CONTENT_LENGTH, partialContentLength.ToString());
                break;

            case ResponseCompressionType.GZip:
                response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                //This means that the output stream will be chunked, so we don't have to worry about content length
                break;

            case ResponseCompressionType.Deflate:
                response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                //This means that the output stream will be chunked, so we don't have to worry about content length
                break;
            }

            response.ContentType = MULTIPART_CONTENTTYPE;
        }
Ejemplo n.º 4
0
        public void SetContentLength(HttpResponseBase response, IEntity entity)
        {
            var contentLength = range.EndRange - range.StartRange + 1;

            HttpResponseHeaderHelper.AppendHeader(response, HTTP_HEADER_CONTENT_LENGTH, contentLength.ToString());
        }
Ejemplo n.º 5
0
        public void SetContentLength(HttpResponseBase response, IEntity entity)
        {
            var partialContentLength = GetMultipartPartialRequestLength(Ranges, entity.ContentType, entity.ContentLength);

            HttpResponseHeaderHelper.AppendHeader(response, HTTP_HEADER_CONTENT_LENGTH, partialContentLength.ToString());
        }