From 53d7ef4014881cee15d399a25cbdb3aee4afad77 Mon Sep 17 00:00:00 2001
From: Taloth Saldono <Taloth@users.noreply.github.com>
Date: Sun, 1 Sep 2019 15:58:01 +0200
Subject: [PATCH] Fixed third-party clients calling api without Accept header

---
 .../GenericApiFixture.cs                      | 51 +++++++++++++++++++
 src/Sonarr.Http/SonarrBootstrapper.cs         |  5 +-
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 src/NzbDrone.Integration.Test/GenericApiFixture.cs

diff --git a/src/NzbDrone.Integration.Test/GenericApiFixture.cs b/src/NzbDrone.Integration.Test/GenericApiFixture.cs
new file mode 100644
index 000000000..d4295a459
--- /dev/null
+++ b/src/NzbDrone.Integration.Test/GenericApiFixture.cs
@@ -0,0 +1,51 @@
+using System.Net;
+using FluentAssertions;
+using NUnit.Framework;
+using NzbDrone.Common.Extensions;
+using NzbDrone.Integration.Test.Client;
+using RestSharp;
+
+namespace NzbDrone.Integration.Test
+{
+    [TestFixture]
+    public class GenericApiFixture : IntegrationTest
+    {
+        [TestCase("application/json")]
+        [TestCase("text/html, application/json")]
+        [TestCase("application/xml, application/json")]
+        [TestCase("text/html, */*")]
+        [TestCase("*/*")]
+        [TestCase("")]
+        public void should_get_json_with_accept_header(string header)
+        {
+
+            var request = new RestRequest("system/status")
+            {
+                RequestFormat = DataFormat.None
+            };
+            request.AddHeader("Accept", header);
+
+            var response = RestClient.Execute(request);
+
+            response.StatusCode.Should().Be(HttpStatusCode.OK);
+            response.ContentType.Should().Be("application/json; charset=utf-8");
+        }
+
+        [TestCase("application/xml")]
+        [TestCase("text/html")]
+        [TestCase("application/junk")]
+        public void should_get_unacceptable_with_accept_header(string header)
+        {
+
+            var request = new RestRequest("system/status")
+            {
+                RequestFormat = DataFormat.None
+            };
+            request.AddHeader("Accept", header);
+
+            var response = RestClient.Execute(request);
+
+            response.StatusCode.Should().Be(HttpStatusCode.NotAcceptable);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/Sonarr.Http/SonarrBootstrapper.cs b/src/Sonarr.Http/SonarrBootstrapper.cs
index 840e6d985..f6c241cf6 100644
--- a/src/Sonarr.Http/SonarrBootstrapper.cs
+++ b/src/Sonarr.Http/SonarrBootstrapper.cs
@@ -57,7 +57,10 @@ namespace Sonarr.Http
             get
             {
                 // We don't support Xml Serialization atm
-                return NancyInternalConfiguration.WithOverrides(x => x.ResponseProcessors.Remove(typeof(XmlProcessor)));
+                return NancyInternalConfiguration.WithOverrides(x => {
+                    x.ResponseProcessors.Remove(typeof(ViewProcessor));
+                    x.ResponseProcessors.Remove(typeof(XmlProcessor));
+                });
             }
         }