feat: add headerOverrides for surgical emulation header replacement#150
Open
DepsCian wants to merge 1 commit into
Open
feat: add headerOverrides for surgical emulation header replacement#150DepsCian wants to merge 1 commit into
DepsCian wants to merge 1 commit into
Conversation
76f09e4 to
448c955
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #145 (second part)
Problem
Users who want to replace specific emulation-injected headers (e.g. override
Acceptwhile keepingUser-Agent,Accept-Language, etc.) currently have no option besidesdisableDefaultHeaders: true— which strips all emulation headers. This forces manual reconstruction of the entire header set, defeating the purpose of browser fingerprinting.Solution
Add
headerOverrides?: HeadersInittoRequestInitandRequestOptions. Headers listed inheaderOverridesreplace matching emulation-injected headers by name, while all other emulation headers are preserved.How it works
JS layer —
headerOverridesis converted toHeaderTuple[]and threaded throughNativeRequestOptionsto the Rust native binding.Rust layer —
RequestOptions.header_overrides: Vec<(String, String)>is applied inmake_request_inner()afterheaders, using the samerequest.header(key, value)call which replaces by name. Bothheadersandheader_overridesshare a singleorig_headerspass to preserve casing.Changes
rust/src/client.rsheader_overridesfield toRequestOptions, merge withheadersin singleorigpassrust/src/lib.rsheaderOverridesfrom JS object intoRequestOptionssrc/types.tsheaderOverrides?: HeadersInittoRequestInitandRequestOptionssrc/wreq-js.tsNativeRequestOptions, thread throughfetch()and legacyrequest()src/test/http/headers.spec.tsTest Results
New tests:
headerOverrides replaces specific emulation headers— verifies Accept is overridden while User-Agent is preservedheaderOverrides with headers coexist— verifies custom headers + overrides + emulation all work togethervs
disableDefaultHeadersdisableDefaultHeaders: trueheaderOverrides