You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: allow removing impersonated headers by passing empty string (#382)
Users can now remove impersonated headers (like `Sec-Fetch-User`) from
requests by passing an empty string as the header value. When an empty
string is provided, the header is filtered out before the request is
sent.
This enables users, e.g., to manually control which `Sec-Fetch-*`
headers should be included in their requests, addressing use cases where
the default impersonated headers don't match the actual request context.
Closes#228
* Can be an object, a Map, or an array of tuples or an instance of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Headers | Headers} class.
349
351
*
350
-
* These headers have the highest priority — they override both client-level headers
351
-
* (set via {@link ImpitOptions.headers}) and browser impersonation headers (set via {@link ImpitOptions.browser}).
352
+
* Note that headers set here will override any default headers set in {@link ImpitOptions.headers}.
353
+
*
352
354
* Header matching is **case-insensitive** — for example, setting `user-agent` here will override
353
355
* the impersonation `User-Agent` header.
356
+
*
357
+
* To remove an impersonated header, pass an empty string as the value.
Copy file name to clipboardExpand all lines: impit-node/src/impit_builder.rs
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -96,6 +96,13 @@ pub struct ImpitOptions<'a> {
96
96
///
97
97
/// Can be an object, a Map, or an array of tuples or an instance of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Headers | Headers} class.
98
98
///
99
+
/// These headers override any browser impersonation headers (set via the {@link ImpitOptions.browser} option)
100
+
/// and are in turn overridden by request-specific headers (set via {@link RequestInit.headers}).
101
+
/// Header matching is **case-insensitive** — for example, setting `user-agent` here will override
102
+
/// the impersonation `User-Agent` header.
103
+
///
104
+
/// To remove an impersonated header, pass an empty string as the value.
Copy file name to clipboardExpand all lines: impit-node/src/request.rs
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,11 @@ pub struct RequestInit {
35
35
/// Can be an object, a Map, or an array of tuples or an instance of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Headers | Headers} class.
36
36
///
37
37
/// Note that headers set here will override any default headers set in {@link ImpitOptions.headers}.
38
+
///
39
+
/// Header matching is **case-insensitive** — for example, setting `user-agent` here will override
40
+
/// the impersonation `User-Agent` header.
41
+
///
42
+
/// To remove an impersonated header, pass an empty string as the value.
Copy file name to clipboardExpand all lines: impit-python/python/impit/impit.pyi
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -484,7 +484,7 @@ class Client:
484
484
cookie_jar: Cookie jar to store cookies in.
485
485
cookies: httpx-compatible cookies object.
486
486
headers: Default HTTP headers to include in requests. These override browser impersonation
487
-
headers and are overridden by per-request headers. Matching is case-insensitive.
487
+
headers and are overridden by per-request headers. Matching is case-insensitive. To remove an impersonated header, pass an empty string as the value.
488
488
local_address: Local address to bind the client to. Useful for testing purposes or when you want to bind the client to a specific network interface.
489
489
Can be an IP address in the format "xxx.xxx.xxx.xxx" (for IPv4) or "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" (for IPv6).
490
490
"""
@@ -504,7 +504,7 @@ class Client:
504
504
url: URL to request
505
505
content: Raw content to send
506
506
data: Form data to send in request body
507
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
507
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
508
508
timeout: Request timeout in seconds (overrides default timeout)
509
509
force_http3: Force HTTP/3 protocol
510
510
"""
@@ -524,7 +524,7 @@ class Client:
524
524
url: URL to request
525
525
content: Raw content to send
526
526
data: Form data to send in request body
527
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
527
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
528
528
timeout: Request timeout in seconds (overrides default timeout)
529
529
force_http3: Force HTTP/3 protocol
530
530
@@ -545,7 +545,7 @@ class Client:
545
545
url: URL to request
546
546
content: Raw content to send
547
547
data: Form data to send in request body
548
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
548
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
549
549
timeout: Request timeout in seconds (overrides default timeout)
550
550
force_http3: Force HTTP/3 protocol
551
551
"""
@@ -565,7 +565,7 @@ class Client:
565
565
url: URL to request
566
566
content: Raw content to send
567
567
data: Form data to send in request body
568
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
568
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
569
569
timeout: Request timeout in seconds (overrides default timeout)
570
570
force_http3: Force HTTP/3 protocol
571
571
"""
@@ -585,7 +585,7 @@ class Client:
585
585
url: URL to request
586
586
content: Raw content to send
587
587
data: Form data to send in request body
588
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
588
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
589
589
timeout: Request timeout in seconds (overrides default timeout)
590
590
force_http3: Force HTTP/3 protocol
591
591
"""
@@ -605,7 +605,7 @@ class Client:
605
605
url: URL to request
606
606
content: Raw content to send
607
607
data: Form data to send in request body
608
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
608
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
609
609
timeout: Request timeout in seconds (overrides default timeout)
610
610
force_http3: Force HTTP/3 protocol
611
611
"""
@@ -625,7 +625,7 @@ class Client:
625
625
url: URL to request
626
626
content: Raw content to send
627
627
data: Form data to send in request body
628
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
628
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
629
629
timeout: Request timeout in seconds (overrides default timeout)
630
630
force_http3: Force HTTP/3 protocol
631
631
"""
@@ -645,7 +645,7 @@ class Client:
645
645
url: URL to request
646
646
content: Raw content to send
647
647
data: Form data to send in request body
648
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
648
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
649
649
timeout: Request timeout in seconds (overrides default timeout)
650
650
force_http3: Force HTTP/3 protocol
651
651
"""
@@ -668,7 +668,7 @@ class Client:
668
668
url: URL to request
669
669
content: Raw content to send
670
670
data: Form data to send in request body
671
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
671
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
672
672
timeout: Request timeout in seconds (overrides default timeout)
673
673
force_http3: Force HTTP/3 protocol
674
674
stream: Whether to return a streaming response (default: False)
@@ -702,7 +702,7 @@ class Client:
702
702
url: URL to request
703
703
content: Raw content to send
704
704
data: Form data to send in request body
705
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
705
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
706
706
timeout: Request timeout in seconds (overrides default timeout)
707
707
force_http3: Force HTTP/3 protocol
708
708
"""
@@ -825,7 +825,7 @@ class AsyncClient:
825
825
cookie_jar: Cookie jar to store cookies in.
826
826
cookies: httpx-compatible cookies object.
827
827
headers: Default HTTP headers to include in requests. These override browser impersonation
828
-
headers and are overridden by per-request headers. Matching is case-insensitive.
828
+
headers and are overridden by per-request headers. Matching is case-insensitive. To remove an impersonated header, pass an empty string as the value.
829
829
local_address: Local address to bind the client to. Useful for testing purposes or when you want to bind the client to a specific network interface.
830
830
Can be an IP address in the format "xxx.xxx.xxx.xxx" (for IPv4) or "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" (for IPv6).
831
831
"""
@@ -845,7 +845,7 @@ class AsyncClient:
845
845
url: URL to request
846
846
content: Raw content to send
847
847
data: Form data to send in request body
848
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
848
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
849
849
timeout: Request timeout in seconds (overrides default timeout)
850
850
force_http3: Force HTTP/3 protocol
851
851
"""
@@ -865,7 +865,7 @@ class AsyncClient:
865
865
url: URL to request
866
866
content: Raw content to send
867
867
data: Form data to send in request body
868
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
868
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
869
869
timeout: Request timeout in seconds (overrides default timeout)
870
870
force_http3: Force HTTP/3 protocol
871
871
@@ -886,7 +886,7 @@ class AsyncClient:
886
886
url: URL to request
887
887
content: Raw content to send
888
888
data: Form data to send in request body
889
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
889
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
890
890
timeout: Request timeout in seconds (overrides default timeout)
891
891
force_http3: Force HTTP/3 protocol
892
892
"""
@@ -906,7 +906,7 @@ class AsyncClient:
906
906
url: URL to request
907
907
content: Raw content to send
908
908
data: Form data to send in request body
909
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
909
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
910
910
timeout: Request timeout in seconds (overrides default timeout)
911
911
force_http3: Force HTTP/3 protocol
912
912
"""
@@ -926,7 +926,7 @@ class AsyncClient:
926
926
url: URL to request
927
927
content: Raw content to send
928
928
data: Form data to send in request body
929
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
929
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
930
930
timeout: Request timeout in seconds (overrides default timeout)
931
931
force_http3: Force HTTP/3 protocol
932
932
"""
@@ -946,7 +946,7 @@ class AsyncClient:
946
946
url: URL to request
947
947
content: Raw content to send
948
948
data: Form data to send in request body
949
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
949
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
950
950
timeout: Request timeout in seconds (overrides default timeout)
951
951
force_http3: Force HTTP/3 protocol
952
952
"""
@@ -966,7 +966,7 @@ class AsyncClient:
966
966
url: URL to request
967
967
content: Raw content to send
968
968
data: Form data to send in request body
969
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
969
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
970
970
timeout: Request timeout in seconds (overrides default timeout)
971
971
force_http3: Force HTTP/3 protocol
972
972
"""
@@ -986,7 +986,7 @@ class AsyncClient:
986
986
url: URL to request
987
987
content: Raw content to send
988
988
data: Form data to send in request body
989
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
989
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
990
990
timeout: Request timeout in seconds (overrides default timeout)
991
991
force_http3: Force HTTP/3 protocol
992
992
"""
@@ -1009,7 +1009,7 @@ class AsyncClient:
1009
1009
url: URL to request
1010
1010
content: Raw content to send
1011
1011
data: Form data to send in request body
1012
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
1012
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
1013
1013
timeout: Request timeout in seconds (overrides default timeout)
1014
1014
force_http3: Force HTTP/3 protocol
1015
1015
stream: Whether to return a streaming response (default: False)
@@ -1043,7 +1043,7 @@ class AsyncClient:
1043
1043
url: URL to request
1044
1044
content: Raw content to send
1045
1045
data: Form data to send in request body
1046
-
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive)
1046
+
headers: HTTP headers for this request. Override both client-level and impersonation headers (case-insensitive). To remove an impersonated header, pass an empty string as the value
1047
1047
timeout: Request timeout in seconds (overrides default timeout)
0 commit comments