Skip to content

[dotnet] Improve handling for missing status code in HTTP interception #15935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/DevTools/v135/V135Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override async Task ContinueRequestWithResponse(HttpRequestData requestDa
var commandSettings = new FulfillRequestCommandSettings()
{
RequestId = requestData.RequestId,
ResponseCode = responseData.StatusCode,
ResponseCode = responseData.StatusCode ?? throw new ArgumentException("Response data status code cannot be missing", nameof(responseData)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to throw loudly instead of concealing issues

};

if (responseData.Headers.Count > 0 || responseData.CookieHeaders.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/DevTools/v136/V136Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override async Task ContinueRequestWithResponse(HttpRequestData requestDa
var commandSettings = new FulfillRequestCommandSettings()
{
RequestId = requestData.RequestId,
ResponseCode = responseData.StatusCode,
ResponseCode = responseData.StatusCode ?? throw new ArgumentException("Response data status code cannot be missing", nameof(responseData)),
};

if (responseData.Headers.Count > 0 || responseData.CookieHeaders.Count > 0)
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/DevTools/v137/V137Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override async Task ContinueRequestWithResponse(HttpRequestData requestDa
var commandSettings = new FulfillRequestCommandSettings()
{
RequestId = requestData.RequestId,
ResponseCode = responseData.StatusCode,
ResponseCode = responseData.StatusCode ?? throw new ArgumentException("Response data status code cannot be missing", nameof(responseData)),
};

if (responseData.Headers.Count > 0 || responseData.CookieHeaders.Count > 0)
Expand Down Expand Up @@ -354,7 +354,7 @@ private void OnFetchRequestPaused(object? sender, Fetch.RequestPausedEventArgs e
RequestId = e.RequestId,
Url = e.Request.Url,
ResourceType = e.ResourceType.ToString(),
StatusCode = e.ResponseStatusCode.GetValueOrDefault(),
StatusCode = e.ResponseStatusCode,
ErrorReason = e.ResponseErrorReason?.ToString()
};

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/HttpResponseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public HttpResponseData()
/// <summary>
/// Gets or sets the numeric status code of the HTTP response.
/// </summary>
public long StatusCode { get; set; }
public long? StatusCode { get; set; }

/// <summary>
/// Gets or sets the body of the HTTP response.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public NetworkResponseReceivedEventArgs(HttpResponseData responseData)
/// <summary>
/// Gets the HTTP status code of the network response.
/// </summary>
public long ResponseStatusCode { get; }
public long? ResponseStatusCode { get; }

/// <summary>
/// Gets the body of the network response.
Expand Down