diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts
index 170761646f..d914b6b22b 100644
--- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts
+++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts
@@ -7,19 +7,22 @@ const httpClientTypeName = 'BrowserHttpMessageHandler';
const httpClientFullTypeName = `${httpClientNamespace}.${httpClientTypeName}`;
let receiveResponseMethod: MethodHandle;
-registerFunction(`${httpClientFullTypeName}.Send`, (id: number, method: string, requestUri: string, body: string | null, headersJson: string | null) => {
- sendAsync(id, method, requestUri, body, headersJson);
+registerFunction(`${httpClientFullTypeName}.Send`, (id: number, method: string, requestUri: string, body: string | null, headersJson: string | null, fetchArgs: RequestInit | null) => {
+ sendAsync(id, method, requestUri, body, headersJson, fetchArgs);
});
-async function sendAsync(id: number, method: string, requestUri: string, body: string | null, headersJson: string | null) {
+async function sendAsync(id: number, method: string, requestUri: string, body: string | null, headersJson: string | null, fetchArgs: RequestInit | null) {
let response: Response;
let responseText: string;
+
+ const requestInit = fetchArgs || {};
+ requestInit.method = method;
+ requestInit.body = body || undefined;
+
try {
- response = await fetch(requestUri, {
- method: method,
- body: body || undefined,
- headers: headersJson ? (JSON.parse(headersJson) as string[][]) : undefined
- });
+ requestInit.headers = headersJson ? (JSON.parse(headersJson) as string[][]) : undefined;
+
+ response = await fetch(requestUri, requestInit);
responseText = await response.text();
} catch (ex) {
dispatchErrorResponse(id, ex.toString());
diff --git a/src/Microsoft.AspNetCore.Blazor.Browser/Http/BrowserHttpMessageHandler.cs b/src/Microsoft.AspNetCore.Blazor.Browser/Http/BrowserHttpMessageHandler.cs
index de00e0a3a5..4bf5dc6c4c 100644
--- a/src/Microsoft.AspNetCore.Blazor.Browser/Http/BrowserHttpMessageHandler.cs
+++ b/src/Microsoft.AspNetCore.Blazor.Browser/Http/BrowserHttpMessageHandler.cs
@@ -22,6 +22,8 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Http
static IDictionary> _pendingRequests
= new Dictionary>();
+ public const string FetchArgs = "BrowserHttpMessageHandler.FetchArgs";
+
///
protected override async Task SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
@@ -36,13 +38,16 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Http
_pendingRequests.Add(id, tcs);
}
+ request.Properties.TryGetValue(FetchArgs, out var fetchArgs);
+
RegisteredFunction.Invoke
+
+
Request referrer:
+ { requestReferrer = (string)value; }) />
+
+
@if (responseStatusCode.HasValue)
@@ -59,6 +65,7 @@
string method = "GET";
string requestBody = "";
List requestHeaders = new List();
+ string requestReferrer = "";
HttpStatusCode? responseStatusCode;
string responseBody;
@@ -87,6 +94,14 @@
}
}
+ if (!string.IsNullOrEmpty(requestReferrer))
+ {
+ requestMessage.Properties[BrowserHttpMessageHandler.FetchArgs] = new
+ {
+ referrer = requestReferrer
+ };
+ }
+
var response = await Http.SendAsync(requestMessage);
responseStatusCode = response.StatusCode;
responseBody = await response.Content.ReadAsStringAsync();
diff --git a/test/testapps/TestServer/Controllers/PersonController.cs b/test/testapps/TestServer/Controllers/PersonController.cs
index f765566e52..9b5bd6f230 100644
--- a/test/testapps/TestServer/Controllers/PersonController.cs
+++ b/test/testapps/TestServer/Controllers/PersonController.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
-using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
@@ -32,6 +31,12 @@ namespace TestServer.Controllers
}
}
+ [HttpGet("referrer")]
+ public string GetReferer()
+ {
+ return $"The referrer is: {Request.Headers["Referer"].ToString()}";
+ }
+
// PUT api/person
[HttpPut]
public Person Put([FromBody, Required] Person person)