Skip to content

Commit 87bf1ad

Browse files
authored
Stringify response headers for intercepted requests (#1142)
1 parent 7394a8e commit 87bf1ad

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/PuppeteerSharp.Tests/NetworkTests/RequestRespondTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,28 @@ await Page.EvaluateFunctionAsync(@"PREFIX =>
9191
var img = await Page.QuerySelectorAsync("img");
9292
Assert.True(ScreenshotHelper.PixelMatch("mock-binary-response.png", await img.ScreenshotDataAsync()));
9393
}
94+
95+
[Fact]
96+
public async Task ShouldStringifyInterceptedRequestResponseHeaders()
97+
{
98+
await Page.SetRequestInterceptionAsync(true);
99+
Page.Request += async (sender, e) =>
100+
{
101+
await e.Request.RespondAsync(new ResponseData
102+
{
103+
Status = HttpStatusCode.OK,
104+
Headers = new Dictionary<string, object>
105+
{
106+
["foo"] = true
107+
},
108+
Body = "Yo, page!"
109+
});
110+
};
111+
112+
var response = await Page.GoToAsync(TestConstants.EmptyPage);
113+
Assert.Equal(HttpStatusCode.OK, response.Status);
114+
Assert.Equal("True", response.Headers["foo"]);
115+
Assert.Equal("Yo, page!", await Page.EvaluateExpressionAsync<string>("document.body.textContent"));
116+
}
94117
}
95118
}

lib/PuppeteerSharp/ResponseData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public string Body
2525
/// <value>The body as binary.</value>
2626
public byte[] BodyData { get; set; }
2727
/// <summary>
28-
/// Response headers.
28+
/// Response headers. Header values will be converted to a string.
2929
/// </summary>
3030
/// <value>Headers.</value>
3131
public Dictionary<string, object> Headers { get; set; }

0 commit comments

Comments
 (0)