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] case insensitive header names in http requests #14095

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

Conversation

iampopovich
Copy link
Contributor

@iampopovich iampopovich commented Jun 6, 2024

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.

Description

I opened PR with initial changes. i have already asked some questions about feature in feature request ticket
I will implement new tests as soon as I get more information about task details

Motivation and Context

according to #12697 I started to discover how to implement this feature

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

Enhancement


Description

  • Normalize header names to lowercase in setHeader method to ensure case-insensitive handling.
  • Normalize header names to lowercase in addHeader method to ensure case-insensitive handling.

Changes walkthrough 📝

Relevant files
Enhancement
HttpMessage.java
Normalize header names to lowercase in HTTP message handling.

java/src/org/openqa/selenium/remote/http/HttpMessage.java

  • Convert header names to lowercase in setHeader method.
  • Convert header names to lowercase in addHeader method.
  • +2/-2     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are limited to a few lines in a single file, modifying header handling to be case-insensitive. The logic is straightforward, but the impact on existing functionality should be carefully evaluated.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Consistency Issue: The PR changes headers to be stored in lowercase, which might affect other parts of the system that rely on the original case format of headers.

    🔒 Security concerns

    No

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a null check for the name parameter to prevent NullPointerException

    Consider adding a null check for the name parameter before converting it to lowercase to
    avoid potential NullPointerException.

    java/src/org/openqa/selenium/remote/http/HttpMessage.java [126]

    +if (name == null) {
    +    throw new IllegalArgumentException("Header name cannot be null");
    +}
     return removeHeader(name).addHeader(name.toLowerCase(), value);
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a null check is crucial to prevent runtime exceptions when the 'name' parameter is null. This is a significant improvement for robustness.

    8
    Best practice
    Use Locale.ROOT in toLowerCase to ensure consistent behavior across locales

    Consider using Locale.ROOT in the toLowerCase method to ensure consistent behavior across
    different locales.

    java/src/org/openqa/selenium/remote/http/HttpMessage.java [126]

    -return removeHeader(name).addHeader(name.toLowerCase(), value);
    +return removeHeader(name).addHeader(name.toLowerCase(Locale.ROOT), value);
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using Locale.ROOT for toLowerCase ensures consistent behavior across different system locales, which is important for the predictability of HTTP header handling.

    7

    @iampopovich iampopovich changed the title initial changes for #12697 feature request [java] case insensitive header names in http requests Jun 6, 2024
    @titusfortner
    Copy link
    Member

    Let's at least wait to merge this after the upcoming release so that Appium can run their tests against nightly and see if it causes them problems before a production release.

    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.

    None yet

    2 participants