2016-10-03 07:55:15 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Web;
|
|
|
|
using WebDAVSharp.Server.Adapters;
|
|
|
|
using WebDAVSharp.Server.Stores;
|
|
|
|
|
|
|
|
namespace WebDAVSharp.Server.MethodHandlers {
|
|
|
|
/// <summary>
|
|
|
|
/// This class implements the <c>OPTIONS</c> HTTP method for WebDAV#.
|
|
|
|
/// </summary>
|
|
|
|
internal class WebDavOptionsMethodHandler : WebDavMethodHandlerBase, IWebDavMethodHandler {
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of the names of the HTTP methods handled by this instance.
|
|
|
|
/// </summary>
|
|
|
|
public IEnumerable<string> Names {
|
|
|
|
get {
|
2017-03-02 14:46:40 +00:00
|
|
|
return new[] { "OPTIONS" };
|
2016-10-03 07:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
public void ProcessRequest(WebDavServer server, HttpContext context, IWebDavStore store, String fileName) {
|
|
|
|
|
2017-03-03 07:49:56 +00:00
|
|
|
List<string> verbsAllowed = new List<string> { "OPTIONS", "TRACE", "GET", "HEAD", "POST", "COPY", "PROPFIND", "LOCK", "UNLOCK" };
|
2016-10-03 07:55:15 +00:00
|
|
|
List<string> verbsPublic = new List<string> { "OPTIONS", "GET", "HEAD", "PROPFIND", "PROPPATCH", "MKCOL", "PUT", "DELETE", "COPY", "MOVE", "LOCK", "UNLOCK" };
|
|
|
|
|
|
|
|
foreach (string verb in verbsAllowed)
|
|
|
|
context.Response.AppendHeader("Allow", verb);
|
|
|
|
|
|
|
|
foreach (string verb in verbsPublic)
|
|
|
|
context.Response.AppendHeader("Public", verb);
|
|
|
|
|
2017-03-03 07:49:56 +00:00
|
|
|
//tell MS Office specifically: yes, this is a WebDAV Server, and yes, we want you to use WebDAV to edit documents
|
|
|
|
//see. https://msdn.microsoft.com/en-us/library/cc250217.aspx
|
|
|
|
//and: http://stackoverflow.com/questions/40460818/ms-office-opens-documents-readonly-with-webdav
|
|
|
|
// or: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_winother/office-opens-documents-readonly-with-webdav/a1a6dbb6-4041-41a6-9701-8c70343da6ce
|
|
|
|
context.Response.AppendHeader("MS-Author-Via", "DAV");
|
|
|
|
|
2016-10-03 07:55:15 +00:00
|
|
|
// Sends 200 OK
|
|
|
|
context.SendSimpleResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|