A class that contains standard HTTP status codes.
Esempio n. 1
0
        /// <summary>
        ///     Flushes all data in the instance to the underlying HttpListenerResponse.
        /// </summary>
        public void FlushResponse()
        {
            // Set the status code
            _response.StatusCode = _statusCode;

            // Fix the description - if no description is found, use the one provided.
            _response.StatusDescription = HttpStatusCodes.GetStatusDescription(_statusCode) ?? _statusDescription;

            // Update to not use HTTP chunked transfer encoding
            _response.ContentLength64 = _responseStream.Length;
            _response.SendChunked     = false;

            // Dump out the response output stream
            var buffer = new byte[4096];
            int bytesRead;

            _responseStream.Position = 0;

            while ((bytesRead = _responseStream.Read(buffer, 0, 4096)) > 0)
            {
                _response.OutputStream.Write(buffer, 0, bytesRead);
            }

            _responseStream.Close();
            _response.OutputStream.Close();
            _response.Close();
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpResponse" /> class.
        /// </summary>
        /// <param name="response">The response.</param>
        public HttpResponse(HttpListenerResponse response)
        {
            _response       = response;
            _responseStream = new MemoryStream();

            _statusCode        = HttpStatusCodes.HttpOk;
            _statusDescription = HttpStatusCodes.GetStatusDescription(_statusCode);
        }