From 5d37d312e043c73a5f6d1db2c1e57a1c1280fb46 Mon Sep 17 00:00:00 2001
From: Andrew Stanton-Nurse <andrew@stanton-nurse.com>
Date: Thu, 31 May 2018 11:38:48 -0700
Subject: [PATCH] Add Content-Type header in HttpClient.ts (#2242) (#2413)

---
 clients/ts/FunctionalTests/TestHub.cs          |  5 +++++
 .../FunctionalTests/ts/HubConnectionTests.ts   | 18 ++++++++++++++++++
 clients/ts/signalr/src/HttpClient.ts           |  2 ++
 3 files changed, 25 insertions(+)

diff --git a/clients/ts/FunctionalTests/TestHub.cs b/clients/ts/FunctionalTests/TestHub.cs
index 6c4275ee910..53230b52702 100644
--- a/clients/ts/FunctionalTests/TestHub.cs
+++ b/clients/ts/FunctionalTests/TestHub.cs
@@ -83,5 +83,10 @@ namespace FunctionalTests
                 String = "hello world",
             };
         }
+
+        public string GetContentTypeHeader()
+        {
+            return Context.GetHttpContext().Request.Headers["Content-Type"];
+        }
     }
 }
diff --git a/clients/ts/FunctionalTests/ts/HubConnectionTests.ts b/clients/ts/FunctionalTests/ts/HubConnectionTests.ts
index b1ad1044816..6a4a84e8530 100644
--- a/clients/ts/FunctionalTests/ts/HubConnectionTests.ts
+++ b/clients/ts/FunctionalTests/ts/HubConnectionTests.ts
@@ -686,6 +686,24 @@ describe("hubConnection", () => {
         }
     });
 
+    it("populates the Content-Type header when sending XMLHttpRequest", async (done) => {
+        const hubConnection = getConnectionBuilder(HttpTransportType.LongPolling, TESTHUB_NOWEBSOCKETS_ENDPOINT_URL)
+            .withHubProtocol(new JsonHubProtocol())
+            .build();
+
+        try {
+            await hubConnection.start();
+
+            // Check what transport was used by asking the server to tell us.
+            expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("LongPolling");
+            // Check to see that the Content-Type header is set the expected value
+            expect(await hubConnection.invoke("GetContentTypeHeader")).toEqual("text/plain;charset=UTF-8");
+            done();
+        } catch (e) {
+            fail(e);
+        }
+    });
+
     function getJwtToken(url: string): Promise<string> {
         return new Promise((resolve, reject) => {
             const xhr = new XMLHttpRequest();
diff --git a/clients/ts/signalr/src/HttpClient.ts b/clients/ts/signalr/src/HttpClient.ts
index 66837a01a02..7fb94fac0a9 100644
--- a/clients/ts/signalr/src/HttpClient.ts
+++ b/clients/ts/signalr/src/HttpClient.ts
@@ -163,6 +163,8 @@ export class DefaultHttpClient extends HttpClient {
             xhr.open(request.method, request.url, true);
             xhr.withCredentials = true;
             xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+            // Explicitly setting the Content-Type header for React Native on Android platform.
+            xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
 
             if (request.headers) {
                 Object.keys(request.headers)
-- 
GitLab