예제 #1
0
        public void SendResponse(byte[] contents)
        {
            //Response.ContentType
            if (RequestHeaders.AllKeys.Contains("Accept-Encoding") && RequestHeaders["Accept-Encoding"].Contains("gzip") && contents.Length > 1024)
            {
                using (var ms = new MemoryStream())
                {
                    using (var zip = new GZipStream(ms, CompressionMode.Compress))
                    {
                        zip.Write(contents, 0, contents.Length);
                    }
                    contents = ms.ToArray();
                }
                Response.Headers["Content-Encoding"] = "gzip";
            }

            Response.ContentLength64 = contents.Length;
            try
            {
                Response.OutputStream.Write(contents, 0, contents.Length);
            }
            catch (Exception)
            {
                //_logger.Error(ex, "Exception Response.OutputStream.Write");
            }
            try
            {
                Response.OutputStream.Close();
            }
            catch (Exception)
            {
                //_logger.Error(ex, "Exception Response.OutputStream.Close");
            }
            Advanced.Close();
        }
예제 #2
0
        public async override Task SendResponseAsync(byte[] contents)
        {
            try
            {
                contents = await CompressContentsAsync(contents);
                ContentLength64 = contents.Length;

                await Advanced.OutputStream.WriteAsync(contents, 0, (int)ContentLength64);
                Advanced.OutputStream.Close();
            }
            catch (StatusCodeException sce)
            {
                StatusCode = sce.StatusCode;
            }
            catch
            {
                Advanced.OutputStream.Close();
                throw;
            }
            finally
            {
                ResponseSent = true;
                Advanced.Close();
            }
        }
예제 #3
0
        public void SendResponse(byte[] contents)
        {
            if (RequestHeaders.AllKeys.Contains("Accept-Encoding") && RequestHeaders["Accept-Encoding"].Contains("gzip") && contents.Length > 1024)
            {
                using (var ms = new MemoryStream())
                {
                    using (var zip = new GZipStream(ms, CompressionMode.Compress))
                    {
                        zip.Write(contents, 0, contents.Length);
                    }
                    contents = ms.ToArray();
                }
                Response.Headers["Content-Encoding"] = "gzip";
            }

            try
            {
                Response.ContentLength64 = contents.Length;
                Response.OutputStream.Write(contents, 0, contents.Length);
            }
            finally
            {
                Response.OutputStream.Close();
                Advanced.Close();
            }
        }
예제 #4
0
        /// <summary>
        /// Write the content to and closes the OutputStream, then closes the response
        /// </summary>
        /// <param name="buffer"></param>
        protected void FlushResponse(byte[] buffer)
        {
            if (RequestHeaders.AllKeys.Contains("Accept-Encoding") && RequestHeaders["Accept-Encoding"].Contains("gzip") && buffer.Length > 1024)
            {
                using (var ms = new MemoryStream())
                {
                    using (var zip = new GZipStream(ms, CompressionMode.Compress))
                    {
                        zip.Write(buffer, 0, buffer.Length);
                    }
                    buffer = ms.ToArray();
                }
                Response.Headers["Content-Encoding"] = "gzip";
            }

            Response.ContentLength64 = buffer.Length;
            Response.OutputStream.Write(buffer, 0, buffer.Length);
            Response.OutputStream.Close();
            Advanced.Close();
        }