WebDAVOptionsMethodHandler.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using WebDAVSharp.Server.Adapters;
  3. using WebDAVSharp.Server.Stores;
  4. namespace WebDAVSharp.Server.MethodHandlers
  5. {
  6. /// <summary>
  7. /// This class implements the <c>OPTIONS</c> HTTP method for WebDAV#.
  8. /// </summary>
  9. internal class WebDavOptionsMethodHandler : WebDavMethodHandlerBase
  10. {
  11. #region Properties
  12. /// <summary>
  13. /// Gets the collection of the names of the HTTP methods handled by this instance.
  14. /// </summary>
  15. public override IEnumerable<string> Names => new[]
  16. {
  17. "OPTIONS"
  18. };
  19. #endregion
  20. #region Functions
  21. /// <summary>
  22. /// Processes the request.
  23. /// </summary>
  24. /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
  25. /// <param name="context">
  26. /// The
  27. /// <see cref="IHttpListenerContext" /> object containing both the request and response
  28. /// objects to use.
  29. /// </param>
  30. /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
  31. public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
  32. {
  33. foreach (string verb in VerbsAllowed)
  34. context.Response.AppendHeader("Allow", verb);
  35. foreach (string verb in VerbsPublic)
  36. context.Response.AppendHeader("Public", verb);
  37. // Sends 200 OK
  38. context.SendSimpleResponse();
  39. }
  40. #endregion
  41. #region Variables
  42. private static readonly List<string> VerbsAllowed = new List<string> {"OPTIONS", "TRACE", "GET", "HEAD", "POST", "COPY", "PROPFIND", "LOCK", "UNLOCK"};
  43. private static readonly List<string> VerbsPublic = new List<string> {"OPTIONS", "GET", "HEAD", "PROPFIND", "PROPPATCH", "MKCOL", "PUT", "DELETE", "COPY", "MOVE", "LOCK", "UNLOCK"};
  44. #endregion
  45. }
  46. }