HttpListenerRequestAdapter.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text;
  6. namespace WebDAVSharp.Server.Adapters
  7. {
  8. /// <summary>
  9. /// This
  10. /// <see cref="IHttpListenerRequest" /> implementation wraps around a
  11. /// <see cref="HttpListenerRequest" /> instance.
  12. /// </summary>
  13. internal sealed class HttpListenerRequestAdapter : IHttpListenerRequest
  14. {
  15. #region Private Variables
  16. private readonly HttpListenerRequest _request;
  17. #endregion
  18. #region Public Functions
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="HttpListenerRequestAdapter" /> class.
  21. /// </summary>
  22. /// <param name="request">The <see cref="HttpListenerRequest" /> to adapt for WebDAV#.</param>
  23. /// <exception cref="System.ArgumentNullException">request</exception>
  24. /// <exception cref="ArgumentNullException"><paramref name="request" /> is <c>null</c>.</exception>
  25. public HttpListenerRequestAdapter(HttpListenerRequest request)
  26. {
  27. if (request == null)
  28. throw new ArgumentNullException(nameof(request));
  29. _request = request;
  30. }
  31. #endregion
  32. #region Properties
  33. /// <summary>
  34. /// Gets the internal instance that was adapted for WebDAV#.
  35. /// </summary>
  36. /// <value>
  37. /// The adapted instance.
  38. /// </value>
  39. public HttpListenerRequest AdaptedInstance => _request;
  40. /// <summary>
  41. /// Gets the client IP address and port number from which the request originated.
  42. /// </summary>
  43. public IPEndPoint RemoteEndPoint => _request.RemoteEndPoint;
  44. /// <summary>
  45. /// Gets the <see cref="Uri" /> object requested by the client.
  46. /// </summary>
  47. public Uri Url => _request.Url;
  48. /// <summary>
  49. /// Gets the HTTP method specified by the client.
  50. /// </summary>
  51. public string HttpMethod => _request.HttpMethod;
  52. /// <summary>
  53. /// Gets the collection of header name/value pairs sent in the request.
  54. /// </summary>
  55. public NameValueCollection Headers => _request.Headers;
  56. /// <summary>
  57. /// Gets a <see cref="Stream" /> that contains the body data sent by the client.
  58. /// </summary>
  59. public Stream InputStream => _request.InputStream;
  60. /// <summary>
  61. /// Gets the content <see cref="Encoding" /> that can be used with data sent with the request.
  62. /// </summary>
  63. public Encoding ContentEncoding => _request.ContentEncoding;
  64. /// <summary>
  65. /// Gets the length of the body data included in the request.
  66. /// </summary>
  67. public long ContentLength64 => _request.ContentLength64;
  68. #endregion
  69. }
  70. }