Esempio n. 1
0
        /// <summary>
        /// Releases the unmanaged resources used by the System.IO.StreamWriter and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        /// <exception cref="System.Text.EncoderFallbackException">The current encoding does not support displaying half of a Unicode surrogate pair.</exception>
        protected override void Dispose(bool disposing)
        {
            this.disposed = true;

            if (this.closeAfterResponse)
            {
                this.clientConnection?.Dispose();
                this.clientConnection = null;
            }

            if (!this.responseSent)
            {
                this.responseSent = true;

                if (!(this.httpServer is null) && !(this.httpRequest is null))
                {
                    if (this.HeaderSent)
                    {
                        this.httpServer.RequestResponded(this.httpRequest, this.statusCode);
                    }
                    else
                    {
                        this.httpServer.RequestResponded(this.httpRequest, 0);
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Represets a response of an HTTP client request.
 /// </summary>
 public HttpResponse()
     : base()
 {
     this.responseStream   = null;
     this.clientConnection = null;
     this.httpServer       = null;
     this.httpRequest      = null;
 }
Esempio n. 3
0
 /// <summary>
 /// Represets a response of an HTTP client request.
 /// </summary>
 /// <param name="ResponseStream">Underlying response stream.</param>
 /// <param name="ClientConnection">Client connection.</param>
 /// <param name="HttpServer">HTTP Server serving the request.</param>
 /// <param name="Request">Request being served.</param>
 internal HttpResponse(IBinaryTransmission ResponseStream, HttpClientConnection ClientConnection, HttpServer HttpServer, HttpRequest Request)
     : base()
 {
     this.responseStream   = ResponseStream;
     this.clientConnection = ClientConnection;
     this.httpServer       = HttpServer;
     this.httpRequest      = Request;
 }
Esempio n. 4
0
        /// <summary>
        /// Represets a response of an HTTP client request.
        /// </summary>
        /// <param name="TransferEncoding">Transfer encoding to use for transfering content to client.</param>
        /// <param name="HttpServer">HTTP Server serving the request.</param>
        /// <param name="Request">Request being served.</param>
        public HttpResponse(TransferEncoding TransferEncoding, HttpServer HttpServer, HttpRequest Request)
            : base()
        {
            this.responseStream          = null;
            this.clientConnection        = null;
            this.desiredTransferEncoding = TransferEncoding;
            this.httpServer  = HttpServer;
            this.httpRequest = Request;

            if (Request != null && Request.Header.TryGetHeaderField("Connection", out HttpField Field) && Field.Value == "close")
            {
                this.closeAfterResponse = true;
                this.SetHeader("Connection", "close");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Releases the unmanaged resources used by the System.IO.StreamWriter and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        /// <exception cref="System.Text.EncoderFallbackException">The current encoding does not support displaying half of a Unicode surrogate pair.</exception>
        protected override void Dispose(bool disposing)
        {
            this.disposed = true;

            if (this.clientConnection != null)
            {
                this.clientConnection.Flush();
            }
            else if (this.responseStream != null)
            {
                this.responseStream.Flush();
            }

            if (this.closeAfterResponse)
            {
                if (this.clientConnection != null)
                {
                    this.clientConnection.Dispose();
                    this.clientConnection = null;
                    this.responseStream   = null;
                }
                else if (this.responseStream != null)
                {
                    this.responseStream.Dispose();
                    this.responseStream = null;
                }
            }

            if (!this.responseSent)
            {
                this.responseSent = true;

                if (this.httpServer != null)
                {
                    if (this.HeaderSent)
                    {
                        this.httpServer.RequestResponded(this.httpRequest, this.statusCode);
                    }
                    else
                    {
                        this.httpServer.RequestResponded(this.httpRequest, 0);
                    }
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Base class for all transfer encodings.
 /// </summary>
 /// <param name="Output">Decoded output.</param>
 /// <param name="ClientConnection">Client connection.</param>
 internal TransferEncoding(IBinaryTransmission Output, HttpClientConnection ClientConnection)
 {
     this.output           = Output;
     this.clientConnection = ClientConnection;
 }
Esempio n. 7
0
 /// <summary>
 /// Base class for all transfer encodings.
 /// </summary>
 /// <param name="Output">Decoded output.</param>
 /// <param name="ClientConnection">Client connection.</param>
 internal TransferEncoding(Stream Output, HttpClientConnection ClientConnection)
 {
     this.output           = Output;
     this.clientConnection = ClientConnection;
 }