83 lines
3.8 KiB
C#
83 lines
3.8 KiB
C#
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 {
|
|
/// <summary>
|
|
/// This class holds extension methods for various types related to WebDAV#.
|
|
/// </summary>
|
|
internal static class WebDavExtensions {
|
|
///// <summary>
|
|
///// Gets the Uri to the parent object.
|
|
///// </summary>
|
|
///// <param name="uri">The <see cref="Uri" /> of a resource, for which the parent Uri should be retrieved.</param>
|
|
///// <returns>
|
|
///// The parent <see cref="Uri" />.
|
|
///// </returns>
|
|
///// <exception cref="System.ArgumentNullException">uri</exception>
|
|
///// <exception cref="System.InvalidOperationException">Cannot get parent of root</exception>
|
|
///// <exception cref="ArgumentNullException"><paramref name="uri" /> is <c>null</c>.</exception>
|
|
///// <exception cref="InvalidOperationException"><paramref name="uri" /> has no parent, it refers to a root resource.</exception>
|
|
//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));
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Sends a simple response with a specified HTTP status code but no content.
|
|
/// </summary>
|
|
/// <param name="context">The <see cref="IHttpListenerContext" /> to send the response through.</param>
|
|
/// <param name="statusCode">The HTTP status code for the response.</param>
|
|
/// <exception cref="System.ArgumentNullException">context</exception>
|
|
/// <exception cref="ArgumentNullException"><paramref name="context" /> is <c>null</c>.</exception>
|
|
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();
|
|
}
|
|
|
|
// /// <summary>
|
|
// /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />.
|
|
// /// </summary>
|
|
// /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param>
|
|
// /// <param name="server">The
|
|
// /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection
|
|
// /// of known prefixes.</param>
|
|
// /// <returns>
|
|
// /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />.
|
|
// /// </returns>
|
|
// /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception>
|
|
// /// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception>
|
|
// 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");
|
|
// }
|
|
|
|
}
|
|
} |