SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.77k stars 8.02k forks source link

[java] case insensitive header names in http requests #14095

Open iampopovich opened 3 weeks ago

iampopovich commented 3 weeks ago

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

Checklist


PR Type

Enhancement


Description


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

    codiumai-pr-agent-pro[bot] commented 3 weeks ago

    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
    codiumai-pr-agent-pro[bot] commented 3 weeks ago

    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]](https://github.com/SeleniumHQ/selenium/pull/14095/files#diff-964afdcb3dadea085ff510cc2d4b3f7bf635dbb38f7581c5889adfdb40d841caR126-R126) ```diff +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]](https://github.com/SeleniumHQ/selenium/pull/14095/files#diff-964afdcb3dadea085ff510cc2d4b3f7bf635dbb38f7581c5889adfdb40d841caR126-R126) ```diff -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
    titusfortner commented 2 weeks ago

    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.