Skip to content

Commit 6853960

Browse files
committed
feature: HttpFullRequest and HttpFullResponse implementation
1 parent 4a9fd48 commit 6853960

File tree

5 files changed

+1233
-494
lines changed

5 files changed

+1233
-494
lines changed

fgex-lib/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def my_filter(raw_packet: RawPacket): #Logging filter
5050

5151
## Data handlers
5252

53-
### RawPacket
53+
### RawPacket
5454
```python
5555
from firegex.nfproxy import RawPacket
5656
```
@@ -111,6 +111,12 @@ from firegex.nfproxy import HttpRequestHeader
111111
```
112112
This handler will be called only when the request headers are complete. It will receive a HttpRequestHeader object with the same properties as HttpRequest.
113113

114+
### HttpFullRequest
115+
```python
116+
from firegex.nfproxy import HttpFullRequest
117+
```
118+
This handler will be called only when the request is complete. It will receive a HttpFullRequest object with the same properties as HttpRequest.
119+
114120
### HttpResponse
115121
```python
116122
from firegex.nfproxy import HttpResponse
@@ -138,3 +144,8 @@ from firegex.nfproxy import HttpResponseHeader
138144
```
139145
This handler will be called only when the response headers are complete. It will receive a HttpResponseHeader object with the same properties as HttpResponse.
140146

147+
### HttpFullResponse
148+
```python
149+
from firegex.nfproxy import HttpFullResponse
150+
```
151+
This handler will be called only when the response is complete. It will receive a HttpFullResponse object with the same properties as HttpResponse.

fgex-lib/firegex/nfproxy/models/__init__.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
from firegex.nfproxy.models.tcp import TCPInputStream, TCPOutputStream, TCPClientStream, TCPServerStream
2-
from firegex.nfproxy.models.http import HttpRequest, HttpResponse, HttpRequestHeader, HttpResponseHeader
1+
from firegex.nfproxy.models.tcp import (
2+
TCPInputStream,
3+
TCPOutputStream,
4+
TCPClientStream,
5+
TCPServerStream,
6+
)
7+
from firegex.nfproxy.models.http import (
8+
HttpRequest,
9+
HttpResponse,
10+
HttpRequestHeader,
11+
HttpResponseHeader,
12+
HttpFullRequest,
13+
HttpFullResponse,
14+
)
315
from firegex.nfproxy.internals.data import RawPacket
416
from enum import Enum
517

@@ -17,15 +29,28 @@
1729
HttpResponse: HttpResponse._fetch_packet,
1830
HttpRequestHeader: HttpRequestHeader._fetch_packet,
1931
HttpResponseHeader: HttpResponseHeader._fetch_packet,
20-
}
32+
HttpFullRequest: HttpFullRequest._fetch_packet,
33+
HttpFullResponse: HttpFullResponse._fetch_packet,
34+
},
2135
}
2236

37+
2338
class Protocols(Enum):
2439
TCP = "tcp"
2540
HTTP = "http"
2641

42+
2743
__all__ = [
2844
"RawPacket",
29-
"TCPInputStream", "TCPOutputStream", "TCPClientStream", "TCPServerStream",
30-
"HttpRequest", "HttpResponse", "HttpRequestHeader", "HttpResponseHeader", "Protocols"
31-
]
45+
"TCPInputStream",
46+
"TCPOutputStream",
47+
"TCPClientStream",
48+
"TCPServerStream",
49+
"HttpRequest",
50+
"HttpResponse",
51+
"HttpRequestHeader",
52+
"HttpResponseHeader",
53+
"HttpFullRequest",
54+
"HttpFullResponse",
55+
"Protocols",
56+
]

fgex-lib/firegex/nfproxy/models/http.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class InternalCallbackHandler:
7373
messages: deque[InternalHTTPMessage] = deque()
7474
_ws_extentions = None
7575
_ws_raised_error = False
76+
release_message_headers = True
7677

7778
def reset_data(self):
7879
self.msg = InternalHTTPMessage()
@@ -604,6 +605,7 @@ def _fetch_packet(cls, internal_data: DataStreamCtx):
604605
if (
605606
not internal_data.call_mem["headers_were_set"]
606607
and parser.msg.headers_complete
608+
and parser.release_message_headers
607609
):
608610
messages_tosend.append(
609611
parser.msg
@@ -641,7 +643,7 @@ def method(self) -> bytes:
641643

642644
@staticmethod
643645
def _parser_class() -> str:
644-
return "full_http"
646+
return "http_module"
645647

646648
def __repr__(self):
647649
return f"<HttpRequest method={self.method} url={self.url} headers={self.headers} body=[{0 if not self.body else len(self.body)} bytes] http_version={self.http_version} keep_alive={self.keep_alive} should_upgrade={self.should_upgrade} headers_complete={self.headers_complete} message_complete={self.message_complete} content_length={self.content_length} stream={self.stream} ws_stream={self.ws_stream}>"
@@ -664,12 +666,46 @@ def status_code(self) -> int:
664666

665667
@staticmethod
666668
def _parser_class() -> str:
667-
return "full_http"
669+
return "http_module"
668670

669671
def __repr__(self):
670672
return f"<HttpResponse status_code={self.status_code} url={self.url} headers={self.headers} body=[{0 if not self.body else len(self.body)} bytes] http_version={self.http_version} keep_alive={self.keep_alive} should_upgrade={self.should_upgrade} headers_complete={self.headers_complete} message_complete={self.message_complete} content_length={self.content_length} stream={self.stream} ws_stream={self.ws_stream}>"
671673

672674

675+
class HttpFullRequest(HttpRequest):
676+
"""
677+
HTTP Request handler
678+
This data handler will be called when the request data is complete
679+
"""
680+
681+
def _contructor_hook(self):
682+
self._parser.release_message_headers = False
683+
684+
@staticmethod
685+
def _parser_class() -> str:
686+
return "http_full"
687+
688+
def __repr__(self):
689+
return f"<HttpFullRequest method={self.method} url={self.url} headers={self.headers} body=[{0 if not self.body else len(self.body)} bytes] http_version={self.http_version} keep_alive={self.keep_alive} should_upgrade={self.should_upgrade} headers_complete={self.headers_complete} message_complete={self.message_complete} content_length={self.content_length} stream={self.stream} ws_stream={self.ws_stream}>"
690+
691+
692+
class HttpFullResponse(HttpResponse):
693+
"""
694+
HTTP Response handler
695+
This data handler will be called when the response data is complete
696+
"""
697+
698+
def _contructor_hook(self):
699+
self._parser.release_message_headers = False
700+
701+
@staticmethod
702+
def _parser_class() -> str:
703+
return "http_full"
704+
705+
def __repr__(self):
706+
return f"<HttpFullResponse status_code={self.status_code} url={self.url} headers={self.headers} body=[{0 if not self.body else len(self.body)} bytes] http_version={self.http_version} keep_alive={self.keep_alive} should_upgrade={self.should_upgrade} headers_complete={self.headers_complete} message_complete={self.message_complete} content_length={self.content_length} stream={self.stream} ws_stream={self.ws_stream}>"
707+
708+
673709
class HttpRequestHeader(HttpRequest):
674710
"""
675711
HTTP Request Header handler
@@ -681,7 +717,7 @@ def _contructor_hook(self):
681717

682718
@staticmethod
683719
def _parser_class() -> str:
684-
return "header_http"
720+
return "http_header"
685721

686722

687723
class HttpResponseHeader(HttpResponse):
@@ -695,4 +731,4 @@ def _contructor_hook(self):
695731

696732
@staticmethod
697733
def _parser_class() -> str:
698-
return "header_http"
734+
return "http_header"

0 commit comments

Comments
 (0)