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