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

Merged
merged 17 commits into from
Nov 8, 2024

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
    Contributor

    qodo-merge-pro bot commented Jun 6, 2024

    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
    Contributor

    qodo-merge-pro bot commented Jun 6, 2024

    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.

    @diemol diemol linked an issue Aug 9, 2024 that may be closed by this pull request
    Copy link
    Member

    @diemol diemol left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Thank you, @iampopovich!

    @diemol
    Copy link
    Member

    diemol commented Aug 9, 2024

    Several tests failed. Can you please check?

    @iampopovich
    Copy link
    Contributor Author

    @diemol sure
    The FederatedCredentialManagementTest could not be executed due to a process creation error on Windows, related to the long path to the executable file. As a result, the test failed three times, despite the successful execution of other tests.
    Screenshot 2024-08-09 at 22 51 06

    This failure occurs frequently in test runs on Windows and is not directly related to the changes in the pull request.

    @iampopovich
    Copy link
    Contributor Author

    i found issue that can help fix it bazelbuild/bazel#19710

    @diemol
    Copy link
    Member

    diemol commented Aug 9, 2024

    @iampopovich
    Copy link
    Contributor Author

    oh...i see
    I mentioned this in the feature request here. The failing tests need to be fixed under the assumption that headers are now case-insensitive. I will correct the existing tests and resubmit them for review.

    Screenshot 2024-08-09 at 23 29 04

    @iampopovich
    Copy link
    Contributor Author

    @diemol please verify my changes in tests
    I tried to preserve the logic of the checks, considering that header names are now case-insensitive. I also fixed the HttpMessage.setHeader method. Previously, it couldn't remove a header because the headers were set in lowercase, while the name was passed in an arbitrary case.

    public M setHeader(String name, String value) {
        return removeHeader(name.toLowerCase()).addHeader(name.toLowerCase(), value);
    }

    @iampopovich
    Copy link
    Contributor Author

    i noticed the problem with the formatting 👀

    @iampopovich
    Copy link
    Contributor Author

    @diemol i fixed the tests with headers

    @iampopovich iampopovich requested a review from diemol September 2, 2024 09:47
    @VietND96 VietND96 merged commit 19a4546 into SeleniumHQ:trunk Nov 8, 2024
    31 checks passed
    @iampopovich iampopovich deleted the case-insensitive-hrader-name branch November 8, 2024 04:41
    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.

    [🚀 Feature]: use lowercase header names
    4 participants