using System;
using System.IO;
using System.Net;
using System.Text;
namespace WebDAVSharp.Server.Adapters
{
///
/// This
/// implementation wraps around a
/// instance.
///
internal sealed class HttpListenerResponseAdapter : IHttpListenerResponse
{
#region Private Variables
private readonly HttpListenerResponse _response;
#endregion
#region Properties
///
/// Gets the internal instance that was adapted for WebDAV#.
///
///
/// The adapted instance.
///
public HttpListenerResponse AdaptedInstance => _response;
///
/// Gets or sets the HTTP status code to be returned to the client.
///
public int StatusCode
{
get { return _response.StatusCode; }
set { _response.StatusCode = value; }
}
///
/// Gets or sets a text description of the HTTP status code returned to the client.
///
public string StatusDescription
{
get { return _response.StatusDescription; }
set { _response.StatusDescription = value ?? string.Empty; }
}
///
/// Gets a object to which a response can be written.
///
public Stream OutputStream => _response.OutputStream;
///
/// Gets or sets the for this response's .
///
public Encoding ContentEncoding
{
get { return _response.ContentEncoding; }
set { _response.ContentEncoding = value; }
}
///
/// Gets or sets the number of bytes in the body data included in the response.
///
public long ContentLength64
{
get { return _response.ContentLength64; }
set { _response.ContentLength64 = value; }
}
#endregion
#region Public Functions
///
/// Initializes a new instance of the class.
///
/// The to adapt for WebDAV#.
/// Response
/// is null.
public HttpListenerResponseAdapter(HttpListenerResponse response)
{
if (response == null)
throw new ArgumentNullException(nameof(response));
_response = response;
}
///
/// Sends the response to the client and releases the resources held by the adapted
/// instance.
///
public void Close()
{
_response.Close();
}
///
/// Appends a value to the specified HTTP header to be sent with the response.
///
/// The name of the HTTP header to append the to.
/// The value to append to the header.
public void AppendHeader(string name, string value)
{
_response.AppendHeader(name, value);
}
#endregion
}
}