/// <summary>
        /// Reads the XML body of the
        /// <see cref="IHttpListenerRequest" />
        /// and converts it to an
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private static XmlDocument GetXmlDocument(IHttpListenerRequest request)
        {
            string requestBody = "";

            try
            {
                StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8);
                requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return(xmlDocument);
                }
            }
            catch (Exception ex)
            {
                WebDavServer.Log.Warning("XmlDocument has not been read correctly: {0}", requestBody);
                throw new WebDavBadRequestException("Malformed XML", ex);
            }

            return(new XmlDocument());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Overwrite header : T or F
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest"/> has the header included</param>
        /// <returns>The <see cref="bool"/> true if overwrite, false if no overwrite</returns>
        public static bool GetOverwriteHeader(IHttpListenerRequest request)
        {
            // get the value of the Overwrite header as a string
            string overwrite = request.Headers["Overwrite"];

            // check if the string is valid and if it equals T
            return(overwrite != null && overwrite.Equals("T"));
            // else, return false
        }
        public static string GetLockTokenHeader(IHttpListenerRequest request)
        {
            if (!request.Headers.AllKeys.Contains("Lock-Token"))
            {
                return(string.Empty);
            }
            string token = request.Headers["Lock-Token"];

            return(token.Substring(1, token.Length - 2));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 创建HttpListenerResponse实例。
 /// </summary>
 /// <param name="request"></param>
 /// <param name="outputStream"></param>
 /// <param name="connection"></param>
 public HttpListenerResponse(IHttpListenerRequest request, System.IO.Stream outputStream, IHttpConnection connection)
 {
     _cookies         = new HttpCookieCollection();
     _headers         = new System.Collections.Specialized.NameValueCollection();
     _connection      = connection;
     _protocolVersion = request.ProtocolVersion;
     _contentEncoding = request.ContentEncoding;
     _outputStream    = outputStream;
     _output          = new HtmlWriter(this);
     _buffer          = true;
     Clear();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the Destination header as an URI
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest"/> has the header included</param>
        /// <returns>The <see cref="Uri"/> containing the destination</returns>
        public static Uri GetDestinationHeader(IHttpListenerRequest request)
        {
            // get the value of the Destination header as a string
            string destinationUri = request.Headers["Destination"];

            // check if the string is valid
            if (!String.IsNullOrEmpty(destinationUri))
            {
                return(new Uri(destinationUri));
            }
            // else, throw exception
            throw new WebDavConflictException();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the Timeout header : Second-number
        /// </summary>
        /// <param name="request">The request with the request included</param>
        /// <returns>The value of the Timeout header as a string</returns>
        public static string GetTimeoutHeader(IHttpListenerRequest request)
        {
            // get the value of the timeout header as a string
            string timeout = request.Headers["Timeout"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (!String.IsNullOrEmpty(timeout) && !timeout.Equals("infinity") &&
                !timeout.Equals("Infinite, Second-4100000000"))
            {
                return(timeout);
            }
            // else, return the timeout value as if it was requested to be 4 days
            return("Second-345600");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
 /// </summary>
 public void Dispose()
 {
     if (_disposed)
     {
         return;
     }
     if (_request != null)
     {
         _request.Dispose();
         _request = null;
     }
     if (_response != null)
     {
         _response.Dispose();
         _response = null;
     }
     _disposed = true;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the XML body of the
        /// <see cref="IHttpListenerRequest" />
        /// and converts it to an
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private XmlDocument GetXmlDocument(IHttpListenerRequest request)
        {
            try
            {
                StreamReader reader      = new StreamReader(request.InputStream, Encoding.UTF8);
                string       requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    var xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return(xmlDocument);
                }
            }
            catch (Exception)
            {
                _log.Warn("XmlDocument has not been read correctly");
            }

            return(new XmlDocument());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the Depth header : 0, 1 or infinity
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerContext" /> with the response included</param>
        /// <returns>
        /// The values 0, 1 or -1 (for infinity)
        /// </returns>
        public static int GetDepthHeader(IHttpListenerRequest request)
        {
            // get the value of the depth header as a string
            string depth = request.Headers["Depth"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (String.IsNullOrEmpty(depth) || depth.Equals("infinity"))
            {
                return(DepthInfinity);
            }
            int value;

            if (!int.TryParse(depth, out value))
            {
                return(DepthInfinity);
            }
            if (value == 0 || value == 1)
            {
                return(value);
            }
            // else, return the infinity value
            return(DepthInfinity);
        }
Ejemplo n.º 10
0
 public void SetRequest(IHttpListenerRequest request)
 {
     Request = request;
 }
        /// <summary>
        /// Gets the Timeout header : Second-number
        /// </summary>
        /// <param name="request">The request with the request included</param>
        /// <returns>The value of the Timeout header as a string</returns>
        public static string GetTimeoutHeader(IHttpListenerRequest request)
        {
            // get the value of the timeout header as a string
            string timeout = request.Headers["Timeout"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (!String.IsNullOrEmpty(timeout) && !timeout.Equals("infinity") &&
                !timeout.Equals("Infinite, Second-4100000000"))
                return timeout;
            // else, return the timeout value as if it was requested to be 4 days
            return "Second-345600";
        }
        /// <summary>
        /// Gets the Destination header as an URI
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest"/> has the header included</param>
        /// <returns>The <see cref="Uri"/> containing the destination</returns>
        public static Uri GetDestinationHeader(IHttpListenerRequest request)
        {
            // get the value of the Destination header as a string
            string destinationUri = request.Headers["Destination"];

            // check if the string is valid 
            if (!String.IsNullOrEmpty(destinationUri))
                return new Uri(destinationUri);
            // else, throw exception
            throw new WebDavConflictException(String.Format("Get destination header null. Request uri: {0} ", request.Url.AbsoluteUri));
        }
 public static string GetLockTokenIfHeader(IHttpListenerRequest request)
 {
     //(<urn:uuid:cfdc70da-7feb-4bfe-8cb7-18f97d8fecb1>)
     return request.Headers.AllKeys.Contains("If") ? request.Headers["If"].Substring(2, request.Headers["If"].Length-4) : string.Empty;
 }
 public static string GetLockTokenHeader(IHttpListenerRequest request)
 {
     if (!request.Headers.AllKeys.Contains("Lock-Token")) return string.Empty;
     string token = request.Headers["Lock-Token"];
     return (token.Substring(1, token.Length - 2));
 }
        /// <summary>
        /// Gets the Depth header : 0, 1 or infinity
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerContext" /> with the response included</param>
        /// <returns>
        /// The values 0, 1 or -1 (for infinity)
        /// </returns>
        public static int GetDepthHeader(IHttpListenerRequest request)
        {
            // get the value of the depth header as a string
            string depth = request.Headers["Depth"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (String.IsNullOrEmpty(depth) || depth.Equals("infinity"))
                return DepthInfinity;
            int value;
            if (!int.TryParse(depth, out value))
                return DepthInfinity;
            if (value == 0 || value == 1)
                return value;
            // else, return the infinity value
            return DepthInfinity;
        }
        /// <summary>
        /// Gets the Overwrite header : T or F
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest"/> has the header included</param>
        /// <returns>The <see cref="bool"/> true if overwrite, false if no overwrite</returns>
        public static bool GetOverwriteHeader(IHttpListenerRequest request)
        {
            // get the value of the Overwrite header as a string
            string overwrite = request.Headers["Overwrite"];

            // check if the string is valid and if it equals T
            return overwrite != null && overwrite.Equals("T");
            // else, return false
        }
        /// <summary>
        ///     Reads the XML body of the
        ///     <see cref="IHttpListenerRequest" />
        ///     and converts it to an
        ///     <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /></param>
        /// <returns>
        ///     The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private static XmlDocument GetXmlDocument(IHttpListenerRequest request)
        {
            try
            {
                string requestBody;
                using (StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8))
                {
                    requestBody = reader.ReadToEnd();
                    reader.Close();
                }

                if (!IsNullOrEmpty(requestBody))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return xmlDocument;
                }
            }
            catch (Exception)
            {
#if DEBUG
                WebDavServer.Log.Warn("XmlDocument has not been read correctly");
#endif
                return new XmlDocument();
            }

            return new XmlDocument();
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 创建HttpListenerContext实例。
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 public HttpListenerContext(IHttpListenerRequest request, IHttpListenerResponse response)
 {
     _request  = request;
     _response = response;
 }
Ejemplo n.º 19
0
 public void Respond(Message message, IHttpListenerRequest request)
 {
     Respond(r =>
     {
         r.ContentType = contentTypeProvider.ContentType(message);
         soapDecoder.FromMessage(r, message, request);
     });
 }
Ejemplo n.º 20
0
 public HttpListenerRequestProxy(IHttpListenerRequest request)
 {
     this.request = request;
 }
Ejemplo n.º 21
0
 public void Respond(string action, object data, IHttpListenerRequest request)
 {
     Respond(r => soapDecoder.FromData(r, action, data, request));
 }
Ejemplo n.º 22
0
 public static Uri GetRequestUri(IHttpListenerRequest request)
 {
     return(HttpUtilities.GetRequestUriInternal(request.Url, request.RawUrl, request.UserHostName));
 }
        /// <summary>
        /// Reads the XML body of the 
        /// <see cref="IHttpListenerRequest" />
        /// and converts it to an 
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private XmlDocument GetXmlDocument(IHttpListenerRequest request)
        {
            try
            {
                StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8);
                string requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    var xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return xmlDocument;
                }
            }
            catch (Exception)
            {
                _log.Warn("XmlDocument has not been read correctly");
            }

            return new XmlDocument();
        }
        /// <summary>
        ///     Gets the Destination header as an URI
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /> has the header included</param>
        /// <returns>The <see cref="Uri" /> containing the destination</returns>
        public static Uri GetDestinationHeader(IHttpListenerRequest request)
        {
            // get the value of the Destination header as a string
            string destinationUri = request.Headers["Destination"];

            // check if the string is valid 
            if (!IsNullOrEmpty(destinationUri))
                return new Uri(destinationUri);
            // else, throw exception
            throw new WebDavConflictException();
        }
 public static string GetLockTokenIfHeader(IHttpListenerRequest request)
 {
     //(<urn:uuid:cfdc70da-7feb-4bfe-8cb7-18f97d8fecb1>)
     return(request.Headers.AllKeys.Contains("If") ? request.Headers["If"].Substring(2, request.Headers["If"].Length - 4) : string.Empty);
 }
Ejemplo n.º 26
0
 public static NephosUriComponents GetNephosUriComponents(IHttpListenerRequest request, string[] hostSuffixes, bool allowPathStyleUri)
 {
     return(HttpRequestAccessorJuly09.GetNephosUriComponents(HttpUtilities.GetRequestUri(request), hostSuffixes, allowPathStyleUri));
 }
        /// <summary>
        /// Reads the XML body of the 
        /// <see cref="IHttpListenerRequest" />
        /// and converts it to an 
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private static XmlDocument GetXmlDocument(IHttpListenerRequest request)
        {
            string requestBody = "";
            try
            {
                StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8);
                requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return xmlDocument;
                }
            }
            catch (Exception ex)
            {
                WebDavServer.Log.WarnFormat("XmlDocument has not been read correctly: {0}", requestBody);
                throw new WebDavBadRequestException("Malformed XML", ex);
            }

            return new XmlDocument();
        }