Skip to content

Commit

Permalink
response.ok should be true for file:// urls (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored and Meir017 committed Jul 11, 2018
1 parent c533738 commit 4b5758f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/PuppeteerSharp.Tests/PageTests/GotoTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -261,5 +262,15 @@ public async Task ShouldWorkWithSelfRequestingPage()
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Contains("self-request.html", response.Url);
}

[Fact]
public async Task ResponseOkShouldBeTrueForFile()
{
var fileToNavigate = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("assets", "file-to-upload.txt"));
var url = new Uri(fileToNavigate).AbsoluteUri;

var response = await Page.GoToAsync(url);
Assert.True(response.Ok);
}
}
}
14 changes: 7 additions & 7 deletions lib/PuppeteerSharp/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal Response(
Headers = new Dictionary<string, object>();
if (headers != null)
{
foreach (KeyValuePair<string, object> keyValue in headers)
foreach (var keyValue in headers)
{
Headers[keyValue.Key] = keyValue.Value;
}
Expand All @@ -46,27 +46,27 @@ internal Response(
/// <summary>
/// Contains the URL of the response.
/// </summary>
public string Url { get; internal set; }
public string Url { get; }
/// <summary>
/// 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; internal set; }
public Dictionary<string, object> Headers { get; }
/// <summary>
/// Contains the status code of the response
/// </summary>
/// <value>The status.</value>
public HttpStatusCode Status { get; internal set; }
public HttpStatusCode Status { get; }
/// <summary>
/// Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
/// </summary>
/// <value><c>true</c> if ok; otherwise, <c>false</c>.</value>
public bool Ok => (int)Status >= 200 && (int)Status <= 299;
public bool Ok => Status == 0 || ((int)Status >= 200 && (int)Status <= 299);
/// <summary>
/// A matching <see cref="Request"/> object.
/// </summary>
/// <value>The request.</value>
public Request Request { get; internal set; }
public Request Request { get; }
/// <summary>
/// True if the response was served from either the browser's disk cache or memory cache.
/// </summary>
Expand All @@ -75,7 +75,7 @@ internal Response(
/// Gets or sets the security details.
/// </summary>
/// <value>The security details.</value>
public SecurityDetails SecurityDetails { get; internal set; }
public SecurityDetails SecurityDetails { get; }
/// <summary>
/// Gets a value indicating whether the <see cref="Response"/> was served by a service worker.
/// </summary>
Expand Down

0 comments on commit 4b5758f

Please sign in to comment.