Skip to content

Commit 4b5758f

Browse files
kblokMeir017
authored andcommitted
response.ok should be true for file:// urls (#384)
1 parent c533738 commit 4b5758f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/PuppeteerSharp.Tests/PageTests/GotoTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Http;
22
using System;
33
using System.Collections.Generic;
4+
using System.IO;
45
using System.Net;
56
using System.Threading.Tasks;
67
using Xunit;
@@ -261,5 +262,15 @@ public async Task ShouldWorkWithSelfRequestingPage()
261262
Assert.Equal(HttpStatusCode.OK, response.Status);
262263
Assert.Contains("self-request.html", response.Url);
263264
}
265+
266+
[Fact]
267+
public async Task ResponseOkShouldBeTrueForFile()
268+
{
269+
var fileToNavigate = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("assets", "file-to-upload.txt"));
270+
var url = new Uri(fileToNavigate).AbsoluteUri;
271+
272+
var response = await Page.GoToAsync(url);
273+
Assert.True(response.Ok);
274+
}
264275
}
265276
}

lib/PuppeteerSharp/Response.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal Response(
3333
Headers = new Dictionary<string, object>();
3434
if (headers != null)
3535
{
36-
foreach (KeyValuePair<string, object> keyValue in headers)
36+
foreach (var keyValue in headers)
3737
{
3838
Headers[keyValue.Key] = keyValue.Value;
3939
}
@@ -46,27 +46,27 @@ internal Response(
4646
/// <summary>
4747
/// Contains the URL of the response.
4848
/// </summary>
49-
public string Url { get; internal set; }
49+
public string Url { get; }
5050
/// <summary>
5151
/// An object with HTTP headers associated with the response. All header names are lower-case.
5252
/// </summary>
5353
/// <value>The headers.</value>
54-
public Dictionary<string, object> Headers { get; internal set; }
54+
public Dictionary<string, object> Headers { get; }
5555
/// <summary>
5656
/// Contains the status code of the response
5757
/// </summary>
5858
/// <value>The status.</value>
59-
public HttpStatusCode Status { get; internal set; }
59+
public HttpStatusCode Status { get; }
6060
/// <summary>
6161
/// Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
6262
/// </summary>
6363
/// <value><c>true</c> if ok; otherwise, <c>false</c>.</value>
64-
public bool Ok => (int)Status >= 200 && (int)Status <= 299;
64+
public bool Ok => Status == 0 || ((int)Status >= 200 && (int)Status <= 299);
6565
/// <summary>
6666
/// A matching <see cref="Request"/> object.
6767
/// </summary>
6868
/// <value>The request.</value>
69-
public Request Request { get; internal set; }
69+
public Request Request { get; }
7070
/// <summary>
7171
/// True if the response was served from either the browser's disk cache or memory cache.
7272
/// </summary>
@@ -75,7 +75,7 @@ internal Response(
7575
/// Gets or sets the security details.
7676
/// </summary>
7777
/// <value>The security details.</value>
78-
public SecurityDetails SecurityDetails { get; internal set; }
78+
public SecurityDetails SecurityDetails { get; }
7979
/// <summary>
8080
/// Gets a value indicating whether the <see cref="Response"/> was served by a service worker.
8181
/// </summary>

0 commit comments

Comments
 (0)