Example #1
0
        internal ProcessResult ProcessRequest()
        {
            byte[]     byteResponse = new byte[0];
            StatusCode statusCode   = StatusCode.OK;
            string     contentType  = "text/html";

            switch (parser.Kind)
            {
            case RequestKind.Action:
            {
                IActionManager manager = ActionManagerFactory.GetManager(parser);
                return(manager.Process(parser));
            }

            case RequestKind.File:
                if (File.Exists(parser.FileName))
                {
                    switch (parser.Extension)
                    {
                    case "ico":
                    {
                        byteResponse = File.ReadAllBytes(parser.FileName);
                        contentType  = "image/ico";
                        break;
                    }

                    case "html":
                    {
                        byteResponse = File.ReadAllBytes(parser.FileName);
                        break;
                    }

                    default:
                    {
                        byteResponse = File.ReadAllBytes(parser.FileName);
                        contentType  = "text/plain";
                        break;
                    }
                    }
                }
                else
                {
                    statusCode = StatusCode.NotFound;
                }
                break;

            case RequestKind.Error:
                statusCode = StatusCode.NotImplemented;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            return(new ProcessResult
            {
                StatusCode = statusCode,
                Bytes = byteResponse,
                ContentType = contentType
            });
        }