using System; using System.Collections.Generic; using System.Linq; using System.Net; using WebDAVSharp.Server.Adapters; using WebDAVSharp.Server.Exceptions; using WebDAVSharp.Server.Stores; namespace WebDAVSharp.Server.MethodHandlers { /// /// This class implements the MKCOL HTTP method for WebDAV#. /// internal class WebDavMkColMethodHandler : WebDavMethodHandlerBase { #region Properties /// /// Gets the collection of the names of the HTTP methods handled by this instance. /// /// /// The names. /// public override IEnumerable Names => new[] { "MKCOL" }; #endregion #region Functions /// /// Processes the request. /// /// The through which the request came in from the client. /// /// The /// object containing both the request and response /// objects to use. /// /// The that the is hosting. /// /// public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store) { if (context.Request.ContentLength64 > 0) throw new WebDavUnsupportedMediaTypeException(); IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url); string collectionName = Uri.UnescapeDataString(context.Request.Url.Segments.Last().TrimEnd('/', '\\')); if (collection.GetItemByName(collectionName) != null) throw new WebDavMethodNotAllowedException(); collection.CreateCollection(collectionName); context.SendSimpleResponse((int) HttpStatusCode.Created); } #endregion } }