From c71ad7c1991c6973de5ab9a908b1b502e014813e Mon Sep 17 00:00:00 2001 From: Sogoss <> Date: Mon, 20 Jul 2026 16:14:07 +0200 Subject: [PATCH] fix(nfproxy): export HttpHistory in nfproxy and ensure list immutability in getters --- fgex-lib/firegex/nfproxy/__init__.py | 10 +++++++++- fgex-lib/firegex/nfproxy/models/http.py | 4 ++-- tests/test_http_history.py | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/fgex-lib/firegex/nfproxy/__init__.py b/fgex-lib/firegex/nfproxy/__init__.py index 99ad65a..67fc9e2 100644 --- a/fgex-lib/firegex/nfproxy/__init__.py +++ b/fgex-lib/firegex/nfproxy/__init__.py @@ -1,5 +1,13 @@ import functools -from firegex.nfproxy.models import RawPacket, TCPInputStream, TCPOutputStream, TCPClientStream, TCPServerStream +from firegex.nfproxy.models import ( + RawPacket, + TCPInputStream, + TCPOutputStream, + TCPClientStream, + TCPServerStream, + HttpHistory, + HttpStreamHistory, +) from firegex.nfproxy.internals.models import Action, FullStreamAction ACCEPT = Action.ACCEPT diff --git a/fgex-lib/firegex/nfproxy/models/http.py b/fgex-lib/firegex/nfproxy/models/http.py index 6ffcd4e..45ec83b 100644 --- a/fgex-lib/firegex/nfproxy/models/http.py +++ b/fgex-lib/firegex/nfproxy/models/http.py @@ -411,12 +411,12 @@ class HttpHistory: @property def requests(self) -> list["HttpFullRequest"]: """List of previous completed HTTP requests""" - return self._requests + return self._requests.copy() @property def responses(self) -> list["HttpFullResponse"]: """List of previous completed HTTP responses""" - return self._responses + return self._responses.copy() @classmethod def _fetch_packet(cls, internal_data: DataStreamCtx): diff --git a/tests/test_http_history.py b/tests/test_http_history.py index e7514e5..80a9f36 100644 --- a/tests/test_http_history.py +++ b/tests/test_http_history.py @@ -264,6 +264,25 @@ def filter_req(req: HttpFullRequest): handle_packet(glob) +def test_http_history_nfproxy_import(): + from firegex.nfproxy import HttpHistory as HH1, HttpStreamHistory as HH2 + assert HH1 is HttpHistory + assert HH2 is HttpStreamHistory + + +def test_http_history_list_mutation(): + history_obj = HttpHistory(requests=["dummy_req"], responses=["dummy_resp"]) + reqs = history_obj.requests + reqs.clear() + assert len(history_obj.requests) == 1 + assert history_obj.requests == ["dummy_req"] + + resps = history_obj.responses + resps.append("extra_resp") + assert len(history_obj.responses) == 1 + assert history_obj.responses == ["dummy_resp"] + + if __name__ == "__main__": test_http_history_model() test_http_history_stream_execution() @@ -272,6 +291,9 @@ if __name__ == "__main__": test_http_history_parameter_order() test_http_history_property_immutability() test_http_history_negative_max_size() + test_http_history_nfproxy_import() + test_http_history_list_mutation() print("All HTTP history unit tests passed successfully!") +