Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
masterluo committed May 30, 2023
2 parents b96cd6c + 6d447f8 commit 90a33e6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ $ python -m pip install ja3requests
Ja3Requests正式支持Python 3.7+

## 参考
- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP)
- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP)
- [HTTP-RFC](https://www.rfc-editor.org/rfc/rfc2068.html)
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP)
- [HTTP-RFC](https://www.rfc-editor.org/rfc/rfc2068.html)
4 changes: 2 additions & 2 deletions ja3requests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions ja3requests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 18 additions & 3 deletions ja3requests/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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.",
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -252,6 +266,7 @@ def send(self):
context.set_payload(
method=self.method,
headers=self.headers,
body=self.data,
)
response = conn.send(context)

Expand Down
14 changes: 14 additions & 0 deletions test/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


0 comments on commit 90a33e6

Please sign in to comment.