pylookyloo 1.27.1__tar.gz → 1.28.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pylookyloo might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pylookyloo
3
- Version: 1.27.1
3
+ Version: 1.28.0
4
4
  Summary: Python CLI and module for Lookyloo
5
5
  License: BSD-3-Clause
6
6
  Author: Raphaël Vinot
@@ -17,6 +17,29 @@ import requests
17
17
 
18
18
  from urllib3.util import Retry
19
19
  from requests.adapters import HTTPAdapter
20
+ from requests.sessions import Session
21
+ from requests.status_codes import codes
22
+
23
+
24
+ class SafeRedirectRePOSTSession(Session):
25
+
26
+ def rebuild_method(self, prepared_request: requests.PreparedRequest, response: requests.Response) -> None:
27
+ # This method will resubmit a POST when we have a http -> https redirect
28
+ if response.status_code == codes.moved and prepared_request.method == 'POST':
29
+ # make sure it is just a redirect http->https and we're not going to a different host
30
+ prec_url = urlparse(response.url)
31
+ next_url = urlparse(prepared_request.url)
32
+
33
+ if (prec_url.netloc != next_url.netloc or prec_url.scheme != 'http'
34
+ or next_url.scheme != 'https'):
35
+ super().rebuild_method(prepared_request, response)
36
+ else:
37
+ # For surely good reasons, requests force-remove the body of the redirected requests unless the statuscode is either 307 or 308
38
+ # https://github.com/psf/requests/issues/1084
39
+ # Doing that makes sure we keep it
40
+ response.status_code = 307
41
+ else:
42
+ super().rebuild_method(prepared_request, response)
20
43
 
21
44
 
22
45
  class PyLookylooError(Exception):
@@ -78,7 +101,7 @@ class Lookyloo():
78
101
  self.root_url = 'http://' + self.root_url
79
102
  if not self.root_url.endswith('/'):
80
103
  self.root_url += '/'
81
- self.session = requests.session()
104
+ self.session = SafeRedirectRePOSTSession()
82
105
  self.session.headers['user-agent'] = useragent if useragent else f'PyLookyloo / {version("pylookyloo")}'
83
106
  if proxies:
84
107
  self.session.proxies.update(proxies)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pylookyloo"
3
- version = "1.27.1"
3
+ version = "1.28.0"
4
4
  description = "Python CLI and module for Lookyloo"
5
5
  authors = [
6
6
  {name="Raphaël Vinot", email="raphael.vinot@circl.lu"}
File without changes
File without changes