WebDAVHeadMethodHandler.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections.Generic;
  2. using System.Net;
  3. using System.Web;
  4. using WebDAVSharp.Server.Adapters;
  5. using WebDAVSharp.Server.Exceptions;
  6. using WebDAVSharp.Server.Stores;
  7. namespace WebDAVSharp.Server.MethodHandlers
  8. {
  9. /// <summary>
  10. /// This class implements the <c>PROPFIND</c> HTTP method for WebDAV#.
  11. /// </summary>
  12. internal class WebDavHeadMethodHandler : WebDavMethodHandlerBase
  13. {
  14. #region Properties
  15. /// <summary>
  16. /// Gets the collection of the names of the HTTP methods handled by this instance.
  17. /// </summary>
  18. /// <value>
  19. /// The names.
  20. /// </value>
  21. public override IEnumerable<string> Names => new[]
  22. {
  23. "HEAD"
  24. };
  25. #endregion
  26. #region Functions
  27. /// <summary>
  28. /// Processes the request.
  29. /// </summary>
  30. /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
  31. /// <param name="context">
  32. /// The
  33. /// <see cref="IHttpListenerContext" /> object containing both the request and response
  34. /// objects to use.
  35. /// </param>
  36. /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
  37. /// <exception cref="WebDavNotFoundException">
  38. /// <para>
  39. /// <paramref name="context" /> specifies a request for a store item that does not exist.
  40. /// </para>
  41. /// <para>- or -</para>
  42. /// <para>
  43. /// <paramref name="context" /> specifies a request for a store item that is not a document.
  44. /// </para>
  45. /// </exception>
  46. /// <exception cref="WebDavConflictException">
  47. /// <paramref name="context" /> specifies a request for a store item using a
  48. /// collection path that does not exist.
  49. /// </exception>
  50. public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
  51. {
  52. // Get the parent collection of the item
  53. IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);
  54. // Get the item from the collection
  55. IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);
  56. /***************************************************************************************************
  57. * Send the response
  58. ***************************************************************************************************/
  59. // HttpStatusCode doesn't contain WebDav status codes, but HttpWorkerRequest can handle these WebDav status codes
  60. context.Response.StatusCode = (int) HttpStatusCode.OK;
  61. context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription((int) HttpStatusCode.OK);
  62. // set the headers of the response
  63. context.Response.ContentLength64 = 0;
  64. context.Response.AppendHeader("Content-Type", "text/html");
  65. context.Response.AppendHeader("Last-Modified", item.ModificationDate.ToUniversalTime().ToString("R"));
  66. context.Response.Close();
  67. }
  68. #endregion
  69. }
  70. }