Skip to content
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

[java] attempt to pass all the headers from the paused request #15535

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

iampopovich
Copy link
Contributor

@iampopovich iampopovich commented Mar 30, 2025

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.

This pull request includes an important change to the continueRequest method in the v134Network.java file. The change enhances the handling of headers when continuing a paused request to ensure that original headers are preserved and new headers are properly applied.

Enhancements to header handling:

Motivation and Context

attempt to fix #15530 issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix


Description

  • Enhanced continueRequest to preserve original headers.

  • Added logic to override headers with new ones if present.

  • Improved handling of paused requests in v134Network.java.


Changes walkthrough 📝

Relevant files
Bug fix
v134Network.java
Enhanced header handling in `continueRequest` method         

java/src/org/openqa/selenium/devtools/v134/v134Network.java

  • Updated continueRequest to add original headers first.
  • Added logic to override headers with new ones.
  • Improved handling of headers in paused requests.
  • +15/-1   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Header Duplication

    The implementation removes headers with case-insensitive matching but adds them with original case. This could lead to unexpected behavior if header names differ only in case. Consider standardizing header case handling.

    headers.removeIf(h -> h.getName().equalsIgnoreCase(name));
    headers.add(new HeaderEntry(name, value));

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 30, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Learned
    best practice
    Add null checks before accessing nested properties to prevent potential NullPointerExceptions

    The code doesn't check if pausedReq, pausedReq.getRequest(), or
    pausedReq.getRequest().getHeaders() could be null before accessing them. This
    could lead to NullPointerExceptions at runtime. Add null checks to ensure safe
    access to these properties.

    java/src/org/openqa/selenium/devtools/v134/v134Network.java [196-199]

    -pausedReq
    -    .getRequest()
    -    .getHeaders()
    -    .forEach((name, value) -> headers.add(new HeaderEntry(name, String.valueOf(value))));
    +if (pausedReq != null && pausedReq.getRequest() != null && pausedReq.getRequest().getHeaders() != null) {
    +  pausedReq
    +      .getRequest()
    +      .getHeaders()
    +      .forEach((name, value) -> headers.add(new HeaderEntry(name, String.valueOf(value))));
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    General
    Improve header value conversion

    The String.valueOf(value) conversion might not be necessary and could cause
    issues if the header value is already a String or has a specific format.
    Consider checking the actual type of the value before conversion or use a more
    appropriate conversion method.

    java/src/org/openqa/selenium/devtools/v134/v134Network.java [196-199]

     pausedReq
         .getRequest()
         .getHeaders()
    -    .forEach((name, value) -> headers.add(new HeaderEntry(name, String.valueOf(value))));
    +    .forEach((name, value) -> headers.add(new HeaderEntry(name, value instanceof String ? (String)value : String.valueOf(value))));
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion improves type handling by checking if the value is already a String before conversion, which could prevent unnecessary conversions and potential formatting issues. While valid, it's a minor optimization with moderate impact on code robustness.

    Low
    • Update

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [🐛 Bug]: Java, WebDriver not adding Content-Type header when doing calls from any browser towards backend
    1 participant