diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer')
7 files changed, 26 insertions, 46 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 3795f4b15..e8bb40ba1 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -79,6 +79,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer _containerAdapter = new ContainerAdapter(applicationHost); } + public string GlobalResponse { get; set; } + public override void Configure(Container container) { HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath; @@ -90,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer {typeof (FileNotFoundException), 404}, {typeof (DirectoryNotFoundException), 404}, {typeof (SecurityException), 401}, - {typeof (UnauthorizedAccessException), 401} + {typeof (UnauthorizedAccessException), 500} }; HostConfig.Instance.DebugMode = true; @@ -336,6 +338,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer return Task.FromResult(true); } + if (!string.IsNullOrWhiteSpace(GlobalResponse)) + { + httpRes.Write(GlobalResponse); + httpRes.ContentType = "text/plain"; + return Task.FromResult(true); + } + var handler = HttpHandlerFactory.GetHandler(httpReq); var remoteIp = httpReq.RemoteIp; diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 961d58eb6..080441dda 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -12,6 +12,7 @@ using System.IO; using System.Net; using System.Text; using System.Threading.Tasks; +using CommonIO; using MimeTypes = MediaBrowser.Model.Net.MimeTypes; namespace MediaBrowser.Server.Implementations.HttpServer @@ -476,7 +477,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer return new StreamWriter(stream, contentType, _logger) { - OnComplete = options.OnComplete + OnComplete = options.OnComplete, + OnError = options.OnError }; } diff --git a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs index 5558c24d7..f038591aa 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer var msg = "HTTP Response " + statusCode + " to " + endPoint + responseTime; - logger.LogMultiline(msg, LogSeverity.Debug, log); + logger.LogMultiline(msg, LogSeverity.Info, log); } } } diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs index b4da40702..f6b14fcab 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs @@ -220,7 +220,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security { if (string.IsNullOrWhiteSpace(token)) { - throw new SecurityException("Access token is invalid or expired."); + throw new SecurityException("Access token is required."); } var info = GetTokenInfo(request); diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs index 80892b96c..509a00ff9 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs @@ -62,52 +62,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security auth.TryGetValue("Version", out version); } - var token = httpReq.Headers["X-MediaBrowser-Token"]; + var token = httpReq.Headers["X-Emby-Token"]; if (string.IsNullOrWhiteSpace(token)) { - token = httpReq.QueryString["api_key"]; + token = httpReq.Headers["X-MediaBrowser-Token"]; } - - // Hack until iOS is updated - // TODO: Remove - if (string.IsNullOrWhiteSpace(client)) - { - var userAgent = httpReq.Headers["User-Agent"] ?? string.Empty; - - if (userAgent.IndexOf("mediabrowserios", StringComparison.OrdinalIgnoreCase) != -1 || - userAgent.IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 || - userAgent.IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1) - { - client = "iOS"; - } - - else if (userAgent.IndexOf("crKey", StringComparison.OrdinalIgnoreCase) != -1) - { - client = "Chromecast"; - } - } - - // Hack until iOS is updated - // TODO: Remove - if (string.IsNullOrWhiteSpace(device)) + if (string.IsNullOrWhiteSpace(token)) { - var userAgent = httpReq.Headers["User-Agent"] ?? string.Empty; - - if (userAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "iPhone"; - } - - else if (userAgent.IndexOf("iPad", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "iPad"; - } - - else if (userAgent.IndexOf("crKey", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "Chromecast"; - } + token = httpReq.QueryString["api_key"]; } var info = new AuthorizationInfo diff --git a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs index fdb27d40d..f8178c115 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs @@ -191,7 +191,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp var type = request.IsWebSocketRequest ? "Web Socket" : "HTTP " + request.HttpMethod; - logger.LogMultiline(type + " " + request.Url, LogSeverity.Debug, log); + logger.LogMultiline(type + " " + request.Url, LogSeverity.Info, log); } private void HandleError(Exception ex, HttpListenerContext context) diff --git a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs index daa5b86d9..a756f4aa8 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs @@ -36,6 +36,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer } public Action OnComplete { get; set; } + public Action OnError { get; set; } /// <summary> /// Initializes a new instance of the <see cref="StreamWriter" /> class. @@ -102,6 +103,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer { Logger.ErrorException("Error streaming data", ex); + if (OnError != null) + { + OnError(); + } + throw; } finally |
