[py] Missing Headers Assignment in Network Class’s _on_request() by shbenzer · Pull Request #15736 · SeleniumHQ/selenium

@shbenzer

@shbenzer shbenzer commented

May 12, 2025

edited by qodo-code-review bot

Loading

User description

🔗 Related Issues

#15735

💥 What does this PR do?

Addresses missing header assignment discovered in #15735 using https://w3c.github.io/webdriver-bidi/#module-network-definition

🔄 Types of changes

  • Bug fix (backwards compatible)

PR Type

Bug fix


Description

  • Fixes missing headers assignment in Network class's _on_request

  • Ensures request headers are properly captured in BiDi events


Changes walkthrough 📝

Relevant files
Bug fix
network.py
Add missing headers assignment in BiDi Network event handling

py/selenium/webdriver/common/bidi/network.py

  • Adds assignment of headers from event data to Request object in
    _on_request callback.
  • Ensures headers are included when creating Request instances for
    network events.
  • +1/-0     

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

    @gabrielcarioca

    @shbenzer shbenzer changed the title [py] Missing Headers Assignment in _on_request() [py] Missing Headers Assignment in Network Class’s _on_request()

    May 13, 2025

    @shbenzer shbenzer marked this pull request as ready for review

    May 13, 2025 12:53

    @qodo-code-review

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    The fix adds a missing header assignment, but there are no tests included to verify that headers are now properly captured in network events.

    headers=event_data.params["request"].get("headers", None),
    headers_size=event_data.params["request"].get("headersSize", None),

    @qodo-code-review

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Learned
    best practice
    Use empty dict as default

    Use an empty dictionary as the default value for headers instead of None. This
    prevents potential NullReferenceExceptions if the code later tries to access the
    headers without checking if it's None first.

    py/selenium/webdriver/common/bidi/network.py [138]

    -headers=event_data.params["request"].get("headers", None),
    +headers=event_data.params["request"].get("headers", {}),
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why:
    Relevant best practice - Initialize collections and properties with safe default values instead of null to prevent NullReferenceExceptions

    Low
    • More

    cgoldberg

    Choose a reason for hiding this comment

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

    LGTM

    navin772

    Choose a reason for hiding this comment

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

    LGTM!

    This was referenced

    Sep 12, 2025

    This was referenced

    Sep 19, 2025

    This was referenced

    Oct 1, 2025

    This was referenced

    Dec 21, 2025

    This was referenced

    Jan 19, 2026

    This was referenced

    Feb 16, 2026

    This was referenced

    Feb 23, 2026