コード例 #1
0
ファイル: MiniWeb.cs プロジェクト: BrunoMVPCosta/EventStore
        private void ReplyWithContent(HttpEntityManager http, string contentLocalPath)
        {
            //NOTE: this is fix for Mono incompatibility in UriTemplate behavior for /a/b{*C}
            if (("/" + contentLocalPath).StartsWith(_localWebRootPath))
                contentLocalPath = contentLocalPath.Substring(_localWebRootPath.Length);

            //_logger.Trace("{0} requested from MiniWeb", contentLocalPath);
            try
            {
                var extensionToContentType = new Dictionary<string, string>
                {
                    { ".png",  "image/png"} ,
                    { ".svg",  "image/svg+xml"} ,
                    { ".woff", "application/x-font-woff"} ,
                    { ".woff2", "application/x-font-woff"} ,
                    { ".ttf", "application/font-sfnt"} ,
                    { ".jpg",  "image/jpeg"} ,
                    { ".jpeg", "image/jpeg"} ,
                    { ".css",  "text/css"} ,
                    { ".htm",  "text/html"} ,
                    { ".html", "text/html"} ,
                    { ".js",   "application/javascript"} ,
                    { ".json",   "application/json"} ,
                    { ".ico",  "image/vnd.microsoft.icon"}
                };

                var extension = Path.GetExtension(contentLocalPath);
                var fullPath = Path.Combine(_fileSystemRoot, contentLocalPath);

                string contentType;
                if (string.IsNullOrEmpty(extension)
                    || !extensionToContentType.TryGetValue(extension.ToLower(), out contentType)
                    || !File.Exists(fullPath))
                {
                    _logger.Info("Replying 404 for {0} ==> {1}", contentLocalPath, fullPath);
                    http.ReplyTextContent(
                        "Not Found", 404, "Not Found", "text/plain", null,
                        ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
                }
                else
                {
                    var config = GetWebPageConfig(contentType);
                    var content = File.ReadAllBytes(fullPath);

                    http.Reply(content,
                                       config.Code,
                                       config.Description,
                                       config.ContentType,
                                       config.Encoding,
                                       config.Headers,
                                       ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
                }
            }
            catch (Exception ex)
            {
                http.ReplyTextContent(ex.ToString(), 500, "Internal Server Error", "text/plain", null, Console.WriteLine);
            }
        }
コード例 #2
0
 private void OnGetOptions(HttpEntityManager entity, UriTemplateMatch match)
 {
     entity.ReplyTextContent(Codec.Json.To(GetOptionsInfo(options)),
                             HttpStatusCode.OK,
                             "OK",
                             entity.ResponseCodec.ContentType,
                             null,
                             e => Log.ErrorException(e, "error while writing http response (options)"));
 }
コード例 #3
0
 private void OnGetPing(HttpEntityManager entity, UriTemplateMatch match)
 {
     var response = new HttpMessage.TextMessage("Ping request successfully handled");
     entity.ReplyTextContent(Format.TextMessage(entity, response),
                             HttpStatusCode.OK,
                             "OK",
                             entity.ResponseCodec.ContentType,
                             null,
                             e => Log.ErrorException(e, "Error while writing HTTP response (ping)"));
 }
コード例 #4
0
 private void OnListNodeSubsystems(HttpEntityManager http, UriTemplateMatch match)
 {
     http.ReplyTextContent(
     Codec.Json.To(_enabledNodeSubsystems),
     200,
     "OK",
     "application/json",
     null,
     ex => Log.InfoException(ex, "Failed to prepare main menu")
     );
 }
コード例 #5
0
ファイル: InfoController.cs プロジェクト: adbrowne/EventStore
 private void OnGetInfo(HttpEntityManager entity, UriTemplateMatch match)
 {
     entity.ReplyTextContent(Codec.Json.To(new
                             {
                                 ESVersion = VersionInfo.Version
                             }),
                             HttpStatusCode.OK,
                             "OK",
                             entity.ResponseCodec.ContentType,
                             null,
                             e => Log.ErrorException(e, "Error while writing http response (info)"));
 }