mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-10 17:43:00 +08:00
fix #1249: catch exceptions when requesting with disabling allow_redirects
This commit is contained in:
@@ -161,13 +161,17 @@
|
||||
- test: add CI test with [github actions][github-actions]
|
||||
- test: integrate [sentry sdk][sentry sdk] for event reporting and analysis
|
||||
|
||||
## 3.1.10 (2022-04-18)
|
||||
|
||||
- fix #1249: catch exceptions when requesting with disabling allow_redirects
|
||||
|
||||
## 3.1.9 (2022-04-17)
|
||||
|
||||
- fix #1174: pydantic validation error when body is None
|
||||
- fix #1209: only convert jmespath path for some fields in white list
|
||||
- fix #1233: parse upload info with session variables
|
||||
- fix #1246: catch exceptions when getting socket address failed
|
||||
- fix #1247: catch exceptions caused by GA report failure
|
||||
- fix #1246: catch exceptions caused by GA report failure
|
||||
- fix #1247: catch exceptions when getting socket address failed
|
||||
|
||||
## 3.1.8 (2022-03-22)
|
||||
|
||||
|
||||
@@ -189,10 +189,11 @@ class HttpSession(requests.Session):
|
||||
|
||||
try:
|
||||
server_ip, server_port = response.raw._connection.sock.getpeername()
|
||||
except Exception:
|
||||
self.data.address.server_ip = server_ip
|
||||
self.data.address.server_port = server_port
|
||||
logger.debug(f"server IP: {server_ip}, Port: {server_port}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# get length of the response content
|
||||
content_size = int(dict(response.headers).get("content-length") or 0)
|
||||
|
||||
68
httprunner/client_test.py
Normal file
68
httprunner/client_test.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import unittest
|
||||
|
||||
from httprunner.client import HttpSession
|
||||
|
||||
|
||||
class TestHttpSession(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.session = HttpSession()
|
||||
|
||||
def test_request_http(self):
|
||||
self.session.request("get", "http://httpbin.org/get")
|
||||
address = self.session.data.address
|
||||
self.assertGreater(len(address.server_ip), 0)
|
||||
self.assertEqual(address.server_port, 80)
|
||||
self.assertGreater(len(address.client_ip), 0)
|
||||
self.assertGreater(address.client_port, 10000)
|
||||
|
||||
def test_request_https(self):
|
||||
self.session.request("get", "https://httpbin.org/get")
|
||||
address = self.session.data.address
|
||||
self.assertGreater(len(address.server_ip), 0)
|
||||
self.assertEqual(address.server_port, 443)
|
||||
self.assertGreater(len(address.client_ip), 0)
|
||||
self.assertGreater(address.client_port, 10000)
|
||||
|
||||
def test_request_http_allow_redirects(self):
|
||||
self.session.request(
|
||||
"get",
|
||||
"http://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||
allow_redirects=True)
|
||||
address = self.session.data.address
|
||||
self.assertNotEqual(address.server_ip, "N/A")
|
||||
self.assertEqual(address.server_port, 443)
|
||||
self.assertNotEqual(address.server_ip, "N/A")
|
||||
self.assertGreater(address.client_port, 10000)
|
||||
|
||||
def test_request_https_allow_redirects(self):
|
||||
self.session.request(
|
||||
"get",
|
||||
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||
allow_redirects=True)
|
||||
address = self.session.data.address
|
||||
self.assertNotEqual(address.server_ip, "N/A")
|
||||
self.assertEqual(address.server_port, 443)
|
||||
self.assertNotEqual(address.server_ip, "N/A")
|
||||
self.assertGreater(address.client_port, 10000)
|
||||
|
||||
def test_request_http_not_allow_redirects(self):
|
||||
self.session.request(
|
||||
"get",
|
||||
"http://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||
allow_redirects=False)
|
||||
address = self.session.data.address
|
||||
self.assertEqual(address.server_ip, "N/A")
|
||||
self.assertEqual(address.server_port, 0)
|
||||
self.assertEqual(address.client_ip, "N/A")
|
||||
self.assertEqual(address.client_port, 0)
|
||||
|
||||
def test_request_https_not_allow_redirects(self):
|
||||
self.session.request(
|
||||
"get",
|
||||
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||
allow_redirects=False)
|
||||
address = self.session.data.address
|
||||
self.assertEqual(address.server_ip, "N/A")
|
||||
self.assertEqual(address.server_port, 0)
|
||||
self.assertEqual(address.client_ip, "N/A")
|
||||
self.assertEqual(address.client_port, 0)
|
||||
Reference in New Issue
Block a user