Skip to content

Commit

Permalink
Add headers tests (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Mar 11, 2019
1 parent 3bfaf8b commit 54629a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
21 changes: 21 additions & 0 deletions lib/PuppeteerSharp.Tests/NetworkTests/RequestHeadersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace PuppeteerSharp.Tests.NetworkTests
{
[Collection("PuppeteerLoaderFixture collection")]
public class RequestHeadersTests : PuppeteerPageBaseTest
{
public RequestHeadersTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ShouldWork()
{
var response = await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Contains("Chrome", response.Request.Headers["User-Agent"]);
}
}
}
27 changes: 27 additions & 0 deletions lib/PuppeteerSharp.Tests/NetworkTests/ResponseHeadersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace PuppeteerSharp.Tests.NetworkTests
{
[Collection("PuppeteerLoaderFixture collection")]
public class ResponseHeadersTests : PuppeteerPageBaseTest
{
public ResponseHeadersTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ShouldWork()
{
Server.SetRoute("/empty.html", (context) =>
{
context.Response.Headers["foo"] = "bar";
return Task.CompletedTask;
});

var response = await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Contains("bar", response.Headers["foo"]);
}
}
}
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/Messaging/ResponsePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace PuppeteerSharp.Messaging
internal class ResponsePayload
{
public string Url { get; set; }
public Dictionary<string, object> Headers { get; set; }
public Dictionary<string, string> Headers { get; set; }
public HttpStatusCode Status { get; set; }
public SecurityDetails SecurityDetails { get; set; }
public bool FromDiskCache { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal Response(
_fromDiskCache = responseMessage.FromDiskCache;
FromServiceWorker = responseMessage.FromServiceWorker;

Headers = new Dictionary<string, object>();
Headers = new Dictionary<string, string>();
if (responseMessage.Headers != null)
{
foreach (var keyValue in responseMessage.Headers)
Expand Down Expand Up @@ -59,7 +59,7 @@ internal Response(
/// An object with HTTP headers associated with the response. All header names are lower-case.
/// </summary>
/// <value>The headers.</value>
public Dictionary<string, object> Headers { get; }
public Dictionary<string, string> Headers { get; }
/// <summary>
/// Contains the status code of the response
/// </summary>
Expand Down

0 comments on commit 54629a6

Please sign in to comment.