allow using predefined Firefox/Chrome 'headers' & 'ciphers'

This commit is contained in:
Mike Fährmann
2025-06-05 13:54:51 +02:00
parent 1866f8b97b
commit efd49aef73
2 changed files with 28 additions and 7 deletions

View File

@@ -726,7 +726,8 @@ Description
extractor.*.headers
-------------------
Type
``object`` (`name` -> `value`)
* ``"string"``
* ``object`` (`name` -> `value`)
Default
.. code:: json
@@ -744,18 +745,23 @@ Description
To disable sending a header, set its value to ``null``.
Set this option to ``"firefox"`` or ``"chrome"``
to use these browser's default headers.
extractor.*.ciphers
-------------------
Type
``list`` of ``strings``
* ``string``
* ``list`` of ``strings``
Example
.. code:: json
* ``"firefox"``
* .. code:: json
["ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES128-GCM-SHA256",
"ECDHE-ECDSA-CHACHA20-POLY1305",
"ECDHE-RSA-CHACHA20-POLY1305"]
["ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES128-GCM-SHA256",
"ECDHE-ECDSA-CHACHA20-POLY1305",
"ECDHE-RSA-CHACHA20-POLY1305"]
Description
List of TLS/SSL cipher suites in
@@ -763,6 +769,9 @@ Description
to be passed to
`ssl.SSLContext.set_ciphers() <https://docs.python.org/3/library/ssl.html#ssl.SSLContext.set_ciphers>`__
Set this option to ``"firefox"`` or ``"chrome"``
to use these browser's default ciphers.
extractor.*.tls12
-----------------

View File

@@ -430,7 +430,10 @@ class Extractor():
headers["User-Agent"] = useragent
headers["Accept"] = "*/*"
headers["Accept-Language"] = "en-US,en;q=0.5"
ssl_ciphers = self.ciphers
if ssl_ciphers is not None and ssl_ciphers in SSL_CIPHERS:
ssl_ciphers = SSL_CIPHERS[ssl_ciphers]
if BROTLI:
headers["Accept-Encoding"] = "gzip, deflate, br"
@@ -448,12 +451,21 @@ class Extractor():
custom_headers = self.config("headers")
if custom_headers:
if isinstance(custom_headers, str):
if custom_headers in HTTP_HEADERS:
custom_headers = HTTP_HEADERS[custom_headers]
else:
self.log.error("Invalid 'headers' value '%s'",
custom_headers)
custom_headers = ()
headers.update(custom_headers)
custom_ciphers = self.config("ciphers")
if custom_ciphers:
if isinstance(custom_ciphers, list):
ssl_ciphers = ":".join(custom_ciphers)
elif custom_ciphers in SSL_CIPHERS:
ssl_ciphers = SSL_CIPHERS[custom_ciphers]
else:
ssl_ciphers = custom_ciphers