From 531642fc534870cb351c04fd4a8e6f8c60673ecc Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 3 Oct 2019 14:05:55 +0300 Subject: [PATCH 1/4] Improve gitattributes for images --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index d78b0459d8..8ae5997258 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,5 @@ * text=auto eol=lf +*.png binary +*.jpg binary CONTRIBUTORS.md merge=union From 33b69a709997924aa2cf8ce06a46939d7243001b Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 9 Oct 2019 13:54:05 +0300 Subject: [PATCH 2/4] Set response length and mime type correctly when reporting an error --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index d60f5c0556..5b1a079302 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -233,8 +233,10 @@ namespace Emby.Server.Implementations.HttpServer var statusCode = GetStatusCode(ex); httpRes.StatusCode = statusCode; - httpRes.ContentType = "text/html"; - await httpRes.WriteAsync(NormalizeExceptionMessage(ex.Message)).ConfigureAwait(false); + var errContent = NormalizeExceptionMessage(ex.Message); + httpRes.ContentType = "text/plain"; + httpRes.ContentLength = errContent.Length; + await httpRes.WriteAsync(errContent).ConfigureAwait(false); } catch (Exception errorEx) { From 8109c7eb303a914db5f034195d12cc8f54d5a6ae Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 9 Oct 2019 14:00:22 +0300 Subject: [PATCH 3/4] Always log at least error message when error happens during request processing --- .../HttpServer/HttpListenerHost.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 5b1a079302..178b1ab825 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -208,7 +208,7 @@ namespace Emby.Server.Implementations.HttpServer } } - private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, bool logExceptionMessage) + private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace) { try { @@ -218,9 +218,9 @@ namespace Emby.Server.Implementations.HttpServer { _logger.LogError(ex, "Error processing request"); } - else if (logExceptionMessage) + else { - _logger.LogError(ex.Message); + _logger.LogError("Error processing request: {0}", ex.Message); } var httpRes = httpReq.Response; @@ -511,22 +511,22 @@ namespace Emby.Server.Implementations.HttpServer } else { - await ErrorHandler(new FileNotFoundException(), httpReq, false, false).ConfigureAwait(false); + await ErrorHandler(new FileNotFoundException(), httpReq, false).ConfigureAwait(false); } } catch (Exception ex) when (ex is SocketException || ex is IOException || ex is OperationCanceledException) { - await ErrorHandler(ex, httpReq, false, false).ConfigureAwait(false); + await ErrorHandler(ex, httpReq, false).ConfigureAwait(false); } catch (SecurityException ex) { - await ErrorHandler(ex, httpReq, false, true).ConfigureAwait(false); + await ErrorHandler(ex, httpReq, false).ConfigureAwait(false); } catch (Exception ex) { var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase); - await ErrorHandler(ex, httpReq, logException, false).ConfigureAwait(false); + await ErrorHandler(ex, httpReq, logException).ConfigureAwait(false); } finally { From 03450f383ffe24d742ffa68c99c70b426081db52 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 9 Oct 2019 14:05:32 +0300 Subject: [PATCH 4/4] Fix template for logging --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 178b1ab825..6f436be949 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -220,7 +220,7 @@ namespace Emby.Server.Implementations.HttpServer } else { - _logger.LogError("Error processing request: {0}", ex.Message); + _logger.LogError("Error processing request: {Message}", ex.Message); } var httpRes = httpReq.Response;