From 3dde1f968ddd101db7b5caefcc10a08a2af14250 Mon Sep 17 00:00:00 2001 From: masterluo Date: Tue, 23 May 2023 19:14:09 +0800 Subject: [PATCH 1/2] feat: post method - Content-Type application/x-www-form-urlencoded --- ja3requests/context.py | 5 +++++ ja3requests/request.py | 21 ++++++++++++++++++--- test/test_session.py | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ja3requests/context.py b/ja3requests/context.py index 1276415..4e5444a 100644 --- a/ja3requests/context.py +++ b/ja3requests/context.py @@ -34,6 +34,11 @@ def message(self): self._message = "\r\n".join([self.start_line, self.put_headers()]) self._message += "\r\n\r\n" + if self.body: + self._message += self.body + + print(self._message) + return self._message.encode() def set_payload(self, **kwargs): diff --git a/ja3requests/request.py b/ja3requests/request.py index 26c5512..4a7dc39 100644 --- a/ja3requests/request.py +++ b/ja3requests/request.py @@ -138,9 +138,23 @@ def ready_params(self): def ready_data(self): """ - Todo: Ready form data. + Ready form data. :return: """ + if self.data: + if self.headers is not None: + content_type = self.headers.get("Content-Type", "") + if content_type == "": + self.headers["Content-Type"] = content_type = "application/x-www-form-urlencoded" + else: + self.headers = default_headers() + self.headers["Content-Type"] = content_type = "application/x-www-form-urlencoded" + + if content_type == "application/x-www-form-urlencoded": + self.data = urlencode(self.data) + self.headers["Content-Length"] = len(self.data) + + print(self.data) def ready_headers(self): """ @@ -156,7 +170,7 @@ def ready_headers(self): new_headers = {} header_list = [] for k, v in self.headers.items(): - header = k.lower() + header = k.title() if header in header_list: warnings.warn( f"Duplicate header: {k}, you should check the request headers.", @@ -196,8 +210,8 @@ def ready(self): self.ready_method() self.ready_url() self.ready_params() - self.ready_data() self.ready_headers() + self.ready_data() self.ready_cookies() self.ready_auth() self.ready_json() @@ -252,6 +266,7 @@ def send(self): context.set_payload( method=self.method, headers=self.headers, + body=self.data, ) response = conn.send(context) diff --git a/test/test_session.py b/test/test_session.py index 8d273fc..4c58859 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -13,6 +13,20 @@ def test_get(self): } self.session.get("http://www.baidu.com") + def test_post_data(self): + + data = { + "username": "admin", + "password": "admin" + } + response = self.session.post("http://127.0.0.1:8080/login", data=data) + print(response) + print(response.status_code) + print(response.headers) + print(response.content) + if __name__ == '__main__': unittest.main() + + From 6d447f813195b6c56e76f0597f5a93272060ae7b Mon Sep 17 00:00:00 2001 From: masterluo Date: Tue, 30 May 2023 11:39:44 +0800 Subject: [PATCH 2/2] releae<1.0.2>: - change version, readme --- README-zh.md | 3 ++- README.md | 5 +++-- ja3requests/__version__.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README-zh.md b/README-zh.md index 7a4bd20..4541f4c 100644 --- a/README-zh.md +++ b/README-zh.md @@ -32,4 +32,5 @@ $ python -m pip install ja3requests Ja3Requests正式支持Python 3.7+ ## 参考 -- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP) \ No newline at end of file +- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP) +- [HTTP-RFC](https://www.rfc-editor.org/rfc/rfc2068.html) \ No newline at end of file diff --git a/README.md b/README.md index 7413ede..e05233b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Ja3Requests -**Ja3Requests** is An http request library that can customize ja3 fingerprints. +**Ja3Requests** is an http request library that can customize ja3 or h2 fingerprints. [中文文档](README-zh.md) @@ -32,4 +32,5 @@ $ python -m pip install ja3requests Ja3Requests officially supports Python 3.7+. ## Reference -- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP) \ No newline at end of file +- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP) +- [HTTP-RFC](https://www.rfc-editor.org/rfc/rfc2068.html) \ No newline at end of file diff --git a/ja3requests/__version__.py b/ja3requests/__version__.py index 57ca74b..937d695 100644 --- a/ja3requests/__version__.py +++ b/ja3requests/__version__.py @@ -6,9 +6,9 @@ """ __title__ = "ja3requests" -__description__ = "An http request library that can customize ja3 fingerprints." +__description__ = "An http request library that can customize ja3 or h2 fingerprints." __url__ = "https://github.com/lxjmaster/ja3requests" -__version__ = "1.0.1" +__version__ = "1.0.2" __author__ = "Mast Luo" __author_email__ = "379501669@qq.com" __license__ = "Apache-2.0 license"