using System.Collections.Generic; 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 { /// /// This class implements the GET HTTP method for WebDAV#. /// internal sealed class WebDavGetMethodHandler : WebDavMethodHandlerBase, IWebDavMethodHandler { /// /// Gets the collection of the names of the verbs handled by this instance. /// /// /// The names. /// public IEnumerable Names => new[] { "GET" }; /// /// 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. /// /// /// /// specifies a request for a store item that does not exist. /// /// - or - /// /// specifies a request for a store item that is not a document. /// /// /// /// specifies a request for a store item using a /// collection path that does not exist. /// public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store) { var collection = GetParentCollection(server, store, context.Request.Url); var item = GetItemFromCollection(collection, context.Request.Url); var doc = item as IWebDavStoreDocument; if (doc == null) throw new WebDavNotFoundException(); var docSize = doc.Size; if (docSize == 0) { context.Response.StatusCode = (int) HttpStatusCode.OK; context.Response.ContentLength64 = 0; } using (var stream = doc.OpenReadStream()) { context.Response.StatusCode = (int) HttpStatusCode.OK; if (docSize > 0) context.Response.ContentLength64 = docSize; var buffer = new byte[4096]; int inBuffer; while ((inBuffer = stream.Read(buffer, 0, buffer.Length)) > 0) context.Response.OutputStream.Write(buffer, 0, inBuffer); } context.Response.Close(); } } }