HttpPlugin¶
HttpPlugin
¶
Bases: BasePlugin
HTTP interception plugin. Requires bigfoot[http] extra.
Patches httpx sync/async transports, requests HTTPAdapter, urllib openers, aiohttp ClientSession (if installed), and asyncio.BaseEventLoop.run_in_executor at the class level. Uses reference counting so nested sandboxes work correctly.
Source code in src/bigfoot/plugins/http.py
config_key
classmethod
¶
load_config
¶
Apply [tool.bigfoot.http] configuration.
Recognized keys: require_response (bool): When True, assert_request() returns an HttpAssertionBuilder requiring .assert_response() to complete the assertion. Default False.
Unknown keys are silently ignored for forward-compatibility. Raises TypeError for require_response with a non-bool value.
Source code in src/bigfoot/plugins/http.py
assert_request
¶
Assert an HTTP request interaction, optionally requiring a chained response assertion.
When require_response is False (the default, or when the instance was
constructed with require_response=False), this method is terminal: it
asserts only the four request fields and returns None.
When require_response is True (either via the per-call argument or the
instance default), this method returns an HttpAssertionBuilder. The
caller must chain .assert_response() on the builder to complete the
assertion with all seven fields.
Source code in src/bigfoot/plugins/http.py
mock_response
¶
mock_response(method, url, *, json=None, body=None, status=200, headers=None, params=None, required=True)
Register a mock response for the given method + URL pair.
Source code in src/bigfoot/plugins/http.py
pass_through
¶
Register a permanent pass-through rule for the given method + URL.
Requests matching this rule are forwarded to the real backend instead of raising UnmockedInteractionError. The interaction is still recorded on the timeline and must be asserted.
The URL must match exactly (scheme, host, path). Query parameters are not considered for pass-through rule matching.
Source code in src/bigfoot/plugins/http.py
activate
¶
Reference-counted class-level patch installation.
assertable_fields
¶
Return the field names required in **expected when asserting an HTTP interaction.
When _asserting_request_only is True (set by the terminal path of
assert_request()), only the four request fields are required.
Otherwise all seven fields are required.