Skip to content

Commit 6ee54f5

Browse files
kblokMeir017
authored andcommitted
Make sure referer header is reported with request interception (#630)
Also Headers should be a `Dictionary<string, string>`
1 parent e2c114c commit 6ee54f5

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public async Task ShouldIntercept()
3939
Assert.True(response.Ok);
4040
}
4141

42+
[Fact]
43+
public async Task ShouldContainRefererHeader()
44+
{
45+
await Page.SetRequestInterceptionAsync(true);
46+
var requests = new List<Request>();
47+
48+
Page.Request += async (sender, e) =>
49+
{
50+
await e.Request.ContinueAsync();
51+
requests.Add(e.Request);
52+
};
53+
54+
await Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html");
55+
Assert.Contains("/one-style.css", requests[1].Url);
56+
Assert.Contains("/one-style.html", requests[1].Headers["Referer"]);
57+
}
58+
4259
[Fact]
4360
public async Task ShouldProperlyReturnNavigationResponseWhenURLHasCookies()
4461
{
@@ -167,8 +184,10 @@ public async Task ShouldAmendHTTPHeaders()
167184
await Page.SetRequestInterceptionAsync(true);
168185
Page.Request += async (sender, e) =>
169186
{
170-
var headers = new Dictionary<string, object>(e.Request.Headers);
171-
headers["FOO"] = "bar";
187+
var headers = new Dictionary<string, string>(e.Request.Headers)
188+
{
189+
["FOO"] = "bar"
190+
};
172191
await e.Request.ContinueAsync(new Payload { Headers = headers });
173192
};
174193
await Page.GoToAsync(TestConstants.EmptyPage);

lib/PuppeteerSharp/Page.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ public Task<Response> GoToAsync(string url, int? timeout = null, WaitUntilNaviga
766766
/// Navigates to an url
767767
/// </summary>
768768
/// <param name="url">URL to navigate page to. The url should include scheme, e.g. https://.</param>
769-
/// <param name="waitUntil">When to consider navigation succeeded.
769+
/// <param name="waitUntil">When to consider navigation succeeded.</param>
770770
/// <returns>Task which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect</returns>
771771
/// <seealso cref="GoToAsync(string, NavigationOptions)"/>
772772
public Task<Response> GoToAsync(string url, WaitUntilNavigation waitUntil)

lib/PuppeteerSharp/Payload.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ namespace PuppeteerSharp
1313
/// </summary>
1414
public class Payload
1515
{
16-
/// <summary>
17-
/// Initializes a new instance of the <see cref="PuppeteerSharp.Payload"/> class.
18-
/// </summary>
19-
public Payload()
20-
{
21-
Headers = new Dictionary<string, object>();
22-
}
23-
2416
/// <summary>
2517
/// Gets or sets the HTTP method.
2618
/// </summary>
@@ -38,7 +30,7 @@ public Payload()
3830
/// </summary>
3931
/// <value>HTTP headers.</value>
4032
[JsonProperty("headers")]
41-
public Dictionary<string, object> Headers { get; set; }
33+
public Dictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();
4234
/// <summary>
4335
/// Gets or sets the URL.
4436
/// </summary>

lib/PuppeteerSharp/Request.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal Request(
5757
Frame = frame;
5858
RedirectChainList = redirectChain;
5959

60-
Headers = new Dictionary<string, object>();
60+
Headers = new Dictionary<string, string>();
6161
foreach (var keyValue in payload.Headers)
6262
{
6363
Headers[keyValue.Key] = keyValue.Value;
@@ -115,7 +115,7 @@ internal Request(
115115
/// Gets or sets the HTTP headers.
116116
/// </summary>
117117
/// <value>HTTP headers.</value>
118-
public Dictionary<string, object> Headers { get; internal set; }
118+
public Dictionary<string, string> Headers { get; internal set; }
119119
/// <summary>
120120
/// Gets or sets the URL.
121121
/// </summary>

0 commit comments

Comments
 (0)