using System; using System.Linq; using System.Net; using System.Web; using WebDAVSharp.Server.Adapters; using WebDAVSharp.Server.Exceptions; using WebDAVSharp.Server.Stores; namespace WebDAVSharp.Server { /// /// This class holds extension methods for various types related to WebDAV#. /// internal static class WebDavExtensions { ///// ///// Gets the Uri to the parent object. ///// ///// The of a resource, for which the parent Uri should be retrieved. ///// ///// The parent . ///// ///// uri ///// Cannot get parent of root ///// is null. ///// has no parent, it refers to a root resource. //public static Uri GetParentUri(this Uri uri) //{ // if (uri == null) // throw new ArgumentNullException("uri"); // if (uri.Segments.Length == 1) // throw new InvalidOperationException("Cannot get parent of root"); // string url = uri.ToString(); // int index = url.Length - 1; // if (url[index] == '/') // index--; // while (url[index] != '/') // index--; // return new Uri(url.Substring(0, index + 1)); //} /// /// Sends a simple response with a specified HTTP status code but no content. /// /// The to send the response through. /// The HTTP status code for the response. /// context /// is null. public static void SendSimpleResponse(this HttpContext context, HttpStatusCode statusCode = HttpStatusCode.OK) { if (context == null) throw new ArgumentNullException("context"); context.Response.StatusCode = (int)statusCode; context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription((int)statusCode); //context.Response.Close(); } // /// // /// Gets the prefix that matches the specified . // /// // /// The to find the most specific prefix for. // /// The // /// that hosts the WebDAV server and holds the collection // /// of known prefixes. // /// // /// The most specific for the given . // /// // /// Unable to find correct server root // /// specifies a that is not known to the . // public static Uri GetPrefixUri(this Uri uri, WebDavServer server) // { ////TODO: (Charly): find better way to get the prefix //return new Uri("http://localhost:53321/"); ////string url = uri.ToString(); //// foreach ( //// string prefix in //// server.Listener.Prefixes.Where( //// prefix => url.StartsWith(uri.ToString(), StringComparison.OrdinalIgnoreCase))) //// return new Uri(prefix); //// throw new WebDavInternalServerException("Unable to find correct server root"); // } } }