示例#1
0
        /// <summary>
        /// Create a status code line from a HTTPStatusCode
        /// </summary>
        public static String HttpStatusCodeToString(HTTPStatusCodes myHTTPStatusCode)
        {
            switch (myHTTPStatusCode)
            {
            case HTTPStatusCodes.Unauthorized:
                return("HTTP/1.1 401 " + HttpStatusCodeToSimpleString(myHTTPStatusCode) + Environment.NewLine + "WWW-Authenticate: Basic realm=\"Intern\"");

            default:
                return("HTTP/1.1 " + ((Int32)myHTTPStatusCode).ToString() + " " + HttpStatusCodeToSimpleString(myHTTPStatusCode));
            }
        }
示例#2
0
        /// <summary>
        /// Create a simple status code line from a HTTPStatusCode
        /// </summary>
        public static String HttpStatusCodeToSimpleString(HTTPStatusCodes myHTTPStatusCode)
        {
            switch (myHTTPStatusCode)
            {
            case HTTPStatusCodes.OK:
                return("OK");

            case HTTPStatusCodes.Created:
                return("Created");

            case HTTPStatusCodes.MultiStatus:
                return("Multi-Status");

            case HTTPStatusCodes.BadRequest:
                return("Bad Request");

            case HTTPStatusCodes.Unauthorized:
                return("Authorization Required");

            case HTTPStatusCodes.NotFound:
                return("Not Found");

            case HTTPStatusCodes.PreconditionFailed:
                return("Precondition Failed");

            case HTTPStatusCodes.RequestUriTooLong:
                return("Request URI Too Long");

            case HTTPStatusCodes.UnprocessableEntity:
                return("Unprocessable Entity");

            case HTTPStatusCodes.Locked:
                return("Locked");

            case HTTPStatusCodes.FailedDependency:
                return("Failed Dependency");

            case HTTPStatusCodes.NotImplemented:
                return("Not Implemented");

            case HTTPStatusCodes.InsufficientStorage:
                return("Insufficient Storage");

            default:
                return(((Int32)myHTTPStatusCode).ToString());
            }
        }
示例#3
0
        /// <summary>
        /// Parses a status from a status line <paramref name="Input"/>
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        public HTTPStatusCodes ParseHttpStatus(String Input)
        {
            HTTPStatusCodes Result = HTTPStatusCodes.Unknown;

            String[] HTTPMethodHeader = Input.Split(new char[] { ' ' });

            if (HTTPMethodHeader.Length < 3)
            {
                return(Result);
            }

            if (Input.StartsWith("HTTP"))
            {
                Result = (HTTPStatusCodes)Enum.Parse(typeof(HTTPStatusCodes), HTTPMethodHeader[1]);
            }
            return(Result);
        }
示例#4
0
        /// <summary>
        /// Create a status code line from a HTTPStatusCode
        /// </summary>
        public static String HttpStatusCodeToString(HTTPStatusCodes myHTTPStatusCode)
        {
            switch (myHTTPStatusCode)
            {

                case HTTPStatusCodes.Unauthorized:
                    return "HTTP/1.1 401 " + HttpStatusCodeToSimpleString(myHTTPStatusCode) + Environment.NewLine + "WWW-Authenticate: Basic realm=\"Intern\"";

                default:
                    return "HTTP/1.1 " + ((Int32) myHTTPStatusCode).ToString() + " " + HttpStatusCodeToSimpleString(myHTTPStatusCode);

            }
        }
示例#5
0
        /// <summary>
        /// Create a simple status code line from a HTTPStatusCode
        /// </summary>
        public static String HttpStatusCodeToSimpleString(HTTPStatusCodes myHTTPStatusCode)
        {
            switch (myHTTPStatusCode)
            {

                case HTTPStatusCodes.OK:
                    return "OK";
                case HTTPStatusCodes.Created:
                    return "Created";
                case HTTPStatusCodes.MultiStatus:
                    return "Multi-Status";
                case HTTPStatusCodes.BadRequest:
                    return "Bad Request";
                case HTTPStatusCodes.Unauthorized:
                    return "Authorization Required";
                case HTTPStatusCodes.NotFound:
                    return "Not Found";
                case HTTPStatusCodes.PreconditionFailed:
                    return "Precondition Failed";
                case HTTPStatusCodes.RequestUriTooLong:
                    return "Request URI Too Long";
                case HTTPStatusCodes.UnprocessableEntity:
                    return "Unprocessable Entity";
                case HTTPStatusCodes.Locked:
                    return "Locked";
                case HTTPStatusCodes.FailedDependency:
                    return "Failed Dependency";
                case HTTPStatusCodes.NotImplemented:
                    return "Not Implemented";
                case HTTPStatusCodes.InsufficientStorage:
                    return "Insufficient Storage";

                default:
                    return ((Int32) myHTTPStatusCode).ToString();

            }
        }
示例#6
0
 /// <summary>
 /// Create a response without any body. You should use this for any error 
 /// </summary>
 /// <param name="HTTPStatusCodes"></param>
 /// <returns>The Response without any body (content)</returns>
 private Byte[] GetResponseWithoutBody(HTTPStatusCodes httpStatusCodes)
 {
     return CreateHeader(httpStatusCodes, 0).ToBytes();
 }
示例#7
0
        /// <summary>
        ///  Create the Header for a Response
        /// </summary>
        /// <param name="httpStatusCode">The HTTP Status of the Request (200 OK | 207 MULTI-STATUS)</param>
        /// <param name="contentLength">The Body length</param>
        /// <returns></returns>
        private HTTPHeader CreateHeader(HTTPStatusCodes httpStatusCode, UInt64 contentLength, ContentType contentType = null)
        {
            var header = HTTPServer.HTTPContext.ResponseHeader;
            header.HttpStatusCode = httpStatusCode;
            header.CacheControl = "no-cache";

            header.ServerName = "sones GraphDS WebDAV";
            header.ContentLength = contentLength;
            header.Headers.Add("DAV", "1, 2, 3");

            if (contentType != null)
            {
                header.ContentType = contentType;
            }

            // MS specific: DAV and MS-FP/4.0 (refers to Microsoft FrontPage Server)
            // header.Headers.Add("MS-Author-Via, "DAV");

            if (HTTPServer.HTTPContext.RequestHeader.KeepAlive)
            {
                header.KeepAlive = true;
            }

            return header;
        }