-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[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
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@@ -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)), |
There was a problem hiding this comment.
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
We should investigate deeper, I have reproduced it locally and see strange behavior. I also tried the same in BiDi implementation, and see correct behavior. So when we see the following: networkInterceptor.NetworkResponseReceived += (sender, args) =>
{
Console.WriteLine($"Received HTTP response: {args.ResponseUrl} with status code: {args.ResponseStatusCode}");
};
What I understand we should not see Gathered some logs: BiDi, NavigateAsync command throws:
CDP, classic NavigateAsync command success:
Given that |
Check out my discovery in the original issue: #15844 (comment) DevTools does not get back any status code. The selenium side of things should handle that scenario. |
Your comment is understandable: Insomnia is not a browser, it just sent request to remote end and got response (401). Browser works differently, and selenium relies on CDP. Let's look closer at CDP logs, and try to understand why we got response without status code. |
This is really key point to investigate, in my head this is absolutely incorrect. |
User description
🔗 Related Issues
Related to (but does not close) #15844
Minor breaking change here, but it is warranted; sometimes the HTTP status code is not present (such as the repro in the linked issue).
💥 What does this PR do?
This PR handles situations where no HTTP status code was returned by a given HTTP call.
🔄 Types of changes
PR Type
Bug fix
Description
Handle missing HTTP status codes in DevTools network interception
Change
StatusCode
property fromlong
tolong?
for nullable supportUpdate DevTools versions v135, v136, v137 to use
GetValueOrDefault()
Fix potential null reference exceptions in network response handling
Changes walkthrough 📝
V135Network.cs
Handle null status codes in v135 network
dotnet/src/webdriver/DevTools/v135/V135Network.cs
ResponseCode
assignment to useGetValueOrDefault()
methodStatusCode
might be null in request fulfillmentV136Network.cs
Handle null status codes in v136 network
dotnet/src/webdriver/DevTools/v136/V136Network.cs
ResponseCode
assignment to useGetValueOrDefault()
methodStatusCode
might be null in request fulfillmentV137Network.cs
Handle null status codes in v137 network
dotnet/src/webdriver/DevTools/v137/V137Network.cs
ResponseCode
assignment to useGetValueOrDefault()
methodGetValueOrDefault()
fromStatusCode
assignment in event handlerStatusCode
might be null in both contextsHttpResponseData.cs
Make StatusCode property nullable
dotnet/src/webdriver/HttpResponseData.cs
StatusCode
property type fromlong
tolong?
NetworkResponseReceivedEventArgs.cs
Make ResponseStatusCode property nullable
dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs
ResponseStatusCode
property type fromlong
tolong?