human_requests.network_analyzer.anomaly_sniffer

Attributes

Classes

WaitSource

Create a collection of name/value pairs.

WaitHeader

HeaderAnomalySniffer

Собирает НЕстандартные заголовки запросов/ответов по всему BrowserContext.

Module Contents

class WaitSource(*args, **kwds)[source]

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

REQUEST[source]
RESPONSE[source]
ALL[source]
class WaitHeader[source]
source: WaitSource[source]
headers: List[str] | None = None[source]
__post_init__() None[source]
UrlFilter[source]
class HeaderAnomalySniffer(
*,
extra_request_allow: Iterable[str] = (),
extra_response_allow: Iterable[str] = (),
allowed_prefixes: Iterable[str] = (),
include_subresources: bool = True,
url_key: Callable[[str], str] | None = None,
url_filter: UrlFilter = None,
)[source]

Собирает НЕстандартные заголовки запросов/ответов по всему BrowserContext.

Использование:

sniffer = HeaderAnomalySniffer() await sniffer.start(ctx) # … действия, которые нужно «послушать» … result = await sniffer.complite()

Результат:
{

“request”: { url: { header: [values…] } }, “response”: { url: { header: [values…] } },

}

async start(ctx: playwright.async_api.BrowserContext) None[source]
async complete() Dict[str, Dict[str, Dict[str, list[str]]]][source]
async wait(
*,
tasks: List[WaitHeader],
timeout_ms: int = 30000,
) Dict[str, Dict[str, Dict[str, list[str]]]][source]

Ждёт, пока в ЛОГЕ аномалий появятся все указанные заголовки (для каждого WaitHeader). Учитываются только записи, прошедшие url_filter и «нестандартность».

tasks:

список условий. Для каждого WaitHeader все его headers должны встретиться хотя бы по одному значению, хотя бы на одном URL. source=REQUEST/RESPONSE/ALL ограничивает источник поиска.

timeout_ms:

общий таймаут ожидания (мс). По таймауту — TimeoutError.

Возвращает:

текущий снапшот (как у complete), НЕ останавливает сниффер.