コード例 #1
0
        public void CloseOutputStream(HttpListenerResponse response)
        {
            try
            {
                var outputStream = response.OutputStream;

                // This is needed with compression
                outputStream.Flush();
                outputStream.Dispose();

                response.Close();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
            }
        }
コード例 #2
0
        public void CloseOutputStream(HttpListenerResponse response)
        {
            try
            {
                var outputStream = response.OutputStream;

                // This is needed with compression
                if (outputStream is ResponseStream)
                {
                    //if (!string.IsNullOrWhiteSpace(GetHeader("Content-Encoding")))
                    {
                        outputStream.Flush();
                    }

                    outputStream.Dispose();
                }
                response.Close();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
            }
        }
コード例 #3
0
        private void DisposeCore()
        {
            byte[]       bytes   = null;
            MemoryStream ms      = GetHeaders(true);
            bool         chunked = _response.SendChunked;

            if (_stream.CanWrite)
            {
                try
                {
                    if (ms != null)
                    {
                        long start = ms.Position;
                        if (chunked && !_trailer_sent)
                        {
                            bytes       = GetChunkSizeBytes(0, true);
                            ms.Position = ms.Length;
                            ms.Write(bytes, 0, bytes.Length);
                        }
                        InternalWrite(ms.GetBuffer(), (int)start, (int)(ms.Length - start));
                        _trailer_sent = true;
                    }
                    else if (chunked && !_trailer_sent)
                    {
                        bytes = GetChunkSizeBytes(0, true);
                        InternalWrite(bytes, 0, bytes.Length);
                        _trailer_sent = true;
                    }
                }
                catch (HttpListenerException)
                {
                    // Ignore error due to connection reset by peer
                }
            }
            _response.Close();
        }