Skip to content

Commit

Permalink
Don't disable cache for auth challenge (#1645)
Browse files Browse the repository at this point in the history
* Don't disable cache for auth challenge

* Add missing assembly references
  • Loading branch information
Androbin authored Mar 15, 2021
1 parent ba33687 commit caa7adf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 28 additions & 2 deletions lib/PuppeteerSharp.Tests/NetworkTests/PageAuthenticateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -64,5 +66,29 @@ await Page.AuthenticateAsync(new Credentials
response = await Page.GoToAsync(TestConstants.CrossProcessUrl + "/empty.html");
Assert.Equal(HttpStatusCode.Unauthorized, response.Status);
}

[Fact]
public async Task ShouldNotDisableCaching()
{
Server.SetAuth("/cached/one-style.css", "user4", "pass4");
Server.SetAuth("/cached/one-style.html", "user4", "pass4");

await Page.AuthenticateAsync(new Credentials
{
Username = "user4",
Password = "pass4"
});

var responses = new Dictionary<string, Response>();
Page.Response += (_, e) => responses[e.Response.Url.Split('/').Last()] = e.Response;

await Page.GoToAsync(TestConstants.ServerUrl + "/cached/one-style.html");
await Page.ReloadAsync();

Assert.Equal(HttpStatusCode.NotModified, responses["one-style.html"].Status);
Assert.False(responses["one-style.html"].FromCache);
Assert.Equal(HttpStatusCode.OK, responses["one-style.css"].Status);
Assert.True(responses["one-style.css"].FromCache);
}
}
}
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal Task SetRequestInterceptionAsync(bool value)
private Task UpdateProtocolCacheDisabledAsync()
=> _client.SendAsync("Network.setCacheDisabled", new NetworkSetCacheDisabledRequest
{
CacheDisabled = _userCacheDisabled || _protocolRequestInterceptionEnabled
CacheDisabled = _userCacheDisabled || _userRequestInterceptionEnabled
});

private async void Client_MessageReceived(object sender, MessageEventArgs e)
Expand Down Expand Up @@ -376,7 +376,7 @@ private void HandleRequestRedirect(Request request, ResponsePayload responseMess
private async Task OnRequestWillBeSentAsync(RequestWillBeSentPayload e)
{
// Request interception doesn't happen for data URLs with Network Service.
if (_protocolRequestInterceptionEnabled && !e.Request.Url.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase))
if (_userRequestInterceptionEnabled && !e.Request.Url.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase))
{
if (_requestIdToInterceptionId.TryRemove(e.RequestId, out var interceptionId))
{
Expand Down

0 comments on commit caa7adf

Please sign in to comment.