You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possible Performance Issue The interceptRequest method creates a new ContinueRequestParameters object for every request, even if no modifications are made. This could be optimized to only create the object when needed.
Error Handling The getHttpMethod method throws an IllegalArgumentException with a generic message when an invalid method is provided. It might be more helpful to include the invalid method in the error message.
Test Coverage Several test methods are ignored for Chrome and Edge browsers. It's important to ensure these tests are eventually implemented for all supported browsers to maintain consistent behavior across platforms.
+private static final Map<String, HttpMethod> METHOD_MAP = Arrays.stream(HttpMethod.values())+ .collect(Collectors.toMap(Enum::name, Function.identity()));+
public static HttpMethod getHttpMethod(String method) {
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
- try {- return HttpMethod.valueOf(method.toUpperCase());- } catch (IllegalArgumentException e) {+ HttpMethod httpMethod = METHOD_MAP.get(method.toUpperCase());+ if (httpMethod == null) {
throw new IllegalArgumentException("No enum constant for method: " + method);
}
+ return httpMethod;
}
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Using a Map for HTTP method lookup can significantly improve performance by avoiding exceptions and providing constant-time complexity for lookups. This is a meaningful optimization for frequently called methods.
8
Use a more efficient data structure for storing and retrieving request handlers
Consider using a more efficient data structure for storing and retrieving request handlers. A TreeMap with URI paths as keys could provide faster lookups compared to iterating through a list of predicates.
Why: The suggestion to use a TreeMap for storing request handlers could improve performance by providing faster lookups. However, the current implementation using a stream may be sufficient for the expected use cases, and the change might introduce unnecessary complexity.
7
Best practice
Use a more specific exception type for invalid HTTP methods
Consider using a more specific exception type instead of IllegalArgumentException when handling invalid HTTP methods in the getHttpMethod method.
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("No enum constant for method: " + method);+ throw new UnsupportedOperationException("Unsupported HTTP method: " + method, e);
}
Apply this suggestion
Suggestion importance[1-10]: 6
Why: Using a more specific exception type like UnsupportedOperationException provides clearer semantics and better communicates the nature of the error. However, this change is not critical and mainly improves code readability and error handling clarity.
6
Possible issue
Add a null check before setting headers in the continue request parameters
Consider adding a check for null or empty headerList before setting headers in the continueRequestParameters to avoid unnecessary method calls.
Why: Adding a null check is a minor improvement as the current code already checks for an empty list. The likelihood of headerList being null is low, but the additional check could prevent potential null pointer exceptions.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Related to #13993
Description
Adding network request handler APIs to allow users to modify/intercept network requests using BiDi.
Motivation and Context
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
RemoteNetwork
class, including methods for adding, removing, and clearing request handlers.status
type fromlong
toint
inResponseData
class and updated relevant methods.NetworkEventsTest
to reflect changes inResponseData
status type.Changes walkthrough 📝
Header.java
Modify constructor visibility in `Header` class
java/src/org/openqa/selenium/bidi/network/Header.java
ResponseData.java
Change `status` type in `ResponseData` class
java/src/org/openqa/selenium/bidi/network/ResponseData.java
status
type fromlong
toint
.fromJson
method to readstatus
asInteger
.Network.java
Add request handler management methods in `Network` interface
java/src/org/openqa/selenium/remote/Network.java
RemoteNetwork.java
Implement request interception in `RemoteNetwork` class
java/src/org/openqa/selenium/remote/RemoteNetwork.java
RequestDetails
class for handling request filters and handlers.HttpMethod.java
Add method to convert string to `HttpMethod`
java/src/org/openqa/selenium/remote/http/HttpMethod.java
getHttpMethod
method to retrieveHttpMethod
from string.WebNetworkTest.java
Add tests for network request handler functionality
java/test/org/openqa/selenium/WebNetworkTest.java
NetworkEventsTest.java
Update tests for `ResponseData` status type change
java/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java
status
type change fromlong
toint
.