Skip to content

[py] Add high-level BiDi network extra headers API#17632

Merged
AutomatedTester merged 1 commit into
trunkfrom
py-bidi-network-extra-headers
Jun 5, 2026
Merged

[py] Add high-level BiDi network extra headers API#17632
AutomatedTester merged 1 commit into
trunkfrom
py-bidi-network-extra-headers

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

@AutomatedTester AutomatedTester commented Jun 5, 2026

🔗 Related Issues

Follows #17629 (authentication handlers); final network-module phase of the BiDi Protocol API Design, following #17619 and #17623.

💥 What does this PR do?

Adds the extra-headers API to driver.network, aligned with the Network Module section of the cross-binding BiDi API design:

driver.network.add_extra_header("x-test", "value")  # merged into every subsequent request
driver.network.remove_extra_header("x-test")
driver.network.clear_extra_headers()
  • BiDi has no dedicated set-extra-headers command, so the headers ride the existing request-handler machinery: while any extra header is set, a dedicated match-everything beforeRequestSent intercept pauses each request and the headers are merged during the registry's reconciliation step — the same single network.continueRequest cycle that applies user handler mutations, so a request paused by both the extra-headers intercept and user handlers is still continued exactly once
  • Lazy lifecycle: the intercept and event subscription exist only while at least one extra header is set (zero overhead otherwise); the docstring calls out the per-request round trip while active
  • Header names are case-insensitive (stored lowercase); an extra header replaces any existing request header of the same name
  • Extra headers are not applied to requests a handler failed or stubbed (they never reach the wire), and survive clear_request_handlers like response/authentication handlers do

🔧 Implementation Notes

  • The headers store lives on RequestHandlerRegistry in py/private/_network_handlers.py with a small _before_resolve hook in the shared registry base; manifest glue stays thin, matching Phases 1–3
  • Sharing the registry's subscription/reconciliation (rather than a standalone manager with its own subscription) makes double-continuing a paused request structurally impossible
  • Verified locally: unit tests plus the full Chrome and Firefox BiDi browser suites (extra-header echo via postman-echo.com/headers, mirroring the existing external-endpoint usage in this file)

🤖 AI assistance

  • AI assisted (complete below)
    • Tool(s): Claude Code
    • What was generated: implementation, tests, and this PR description, pair-programmed with the author
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

  • High-risk area touched: wire-level BiDi network semantics (intercept lifecycle, continueRequest header merging)
  • Java/Ruby/JS/.NET parity for the cross-binding design remains follow-up work (Python is leading)

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

@selenium-ci selenium-ci added the C-py Python Bindings label Jun 5, 2026
Base automatically changed from py-bidi-network-auth-handlers to trunk June 5, 2026 11:19
@AutomatedTester AutomatedTester force-pushed the py-bidi-network-extra-headers branch from 6ebf38f to 81afab8 Compare June 5, 2026 11:21
@AutomatedTester AutomatedTester merged commit 9d301b1 into trunk Jun 5, 2026
39 of 41 checks passed
@AutomatedTester AutomatedTester deleted the py-bidi-network-extra-headers branch June 5, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants