feat(Fetcher): Add the redirections history to Fetcher
Feature requested in #32
This commit is contained in:
@@ -72,6 +72,7 @@ class StaticEngine:
|
|||||||
headers=dict(response.headers),
|
headers=dict(response.headers),
|
||||||
request_headers=dict(response.request.headers),
|
request_headers=dict(response.request.headers),
|
||||||
method=response.request.method,
|
method=response.request.method,
|
||||||
|
history=[self._prepare_response(redirection) for redirection in response.history],
|
||||||
**self.adaptor_arguments
|
**self.adaptor_arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -85,13 +85,14 @@ class Response(Adaptor):
|
|||||||
"""This class is returned by all engines as a way to unify response type between different libraries."""
|
"""This class is returned by all engines as a way to unify response type between different libraries."""
|
||||||
|
|
||||||
def __init__(self, url: str, text: str, body: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict,
|
def __init__(self, url: str, text: str, body: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict,
|
||||||
encoding: str = 'utf-8', method: str = 'GET', **adaptor_arguments: Dict):
|
encoding: str = 'utf-8', method: str = 'GET', history: List = None, **adaptor_arguments: Dict):
|
||||||
automatch_domain = adaptor_arguments.pop('automatch_domain', None)
|
automatch_domain = adaptor_arguments.pop('automatch_domain', None)
|
||||||
self.status = status
|
self.status = status
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.cookies = cookies
|
self.cookies = cookies
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
self.request_headers = request_headers
|
self.request_headers = request_headers
|
||||||
|
self.history = history or []
|
||||||
encoding = ResponseEncoding.get_value(encoding, text)
|
encoding = ResponseEncoding.get_value(encoding, text)
|
||||||
super().__init__(text=text, body=body, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
super().__init__(text=text, body=body, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
||||||
# For back-ward compatibility
|
# For back-ward compatibility
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@ class Adaptor(SelectorsGeneration):
|
|||||||
self.__tag = None
|
self.__tag = None
|
||||||
# No need to check if all response attributes exist or not because if `status` exist, then the rest exist (Save some CPU cycles for speed)
|
# No need to check if all response attributes exist or not because if `status` exist, then the rest exist (Save some CPU cycles for speed)
|
||||||
self.__response_data = {
|
self.__response_data = {
|
||||||
key: getattr(self, key) for key in ('status', 'reason', 'cookies', 'headers', 'request_headers',)
|
key: getattr(self, key) for key in ('status', 'reason', 'cookies', 'history', 'headers', 'request_headers',)
|
||||||
} if hasattr(self, 'status') else {}
|
} if hasattr(self, 'status') else {}
|
||||||
|
|
||||||
# Node functionalities, I wanted to move to separate Mixin class but it had slight impact on performance
|
# Node functionalities, I wanted to move to separate Mixin class but it had slight impact on performance
|
||||||
|
|||||||
Reference in New Issue
Block a user