Allow bypass of content-type check in utils.http.request
This commit is contained in:
parent
73fd3f37ce
commit
20042edfd9
1 changed files with 3 additions and 3 deletions
|
@ -59,7 +59,7 @@ def request(url: str, method: str="GET", get_params: dict={},
|
||||||
post_data: typing.Any=None, headers: dict={},
|
post_data: typing.Any=None, headers: dict={},
|
||||||
json_data: typing.Any=None, code: bool=False, json: bool=False,
|
json_data: typing.Any=None, code: bool=False, json: bool=False,
|
||||||
soup: bool=False, parser: str="lxml", fallback_encoding: str="utf8",
|
soup: bool=False, parser: str="lxml", fallback_encoding: str="utf8",
|
||||||
allow_redirects: bool=True
|
allow_redirects: bool=True, check_content_type: bool=True
|
||||||
) -> Response:
|
) -> Response:
|
||||||
|
|
||||||
if not urllib.parse.urlparse(url).scheme:
|
if not urllib.parse.urlparse(url).scheme:
|
||||||
|
@ -96,12 +96,12 @@ def request(url: str, method: str="GET", get_params: dict={},
|
||||||
return response_content.decode(response.encoding or fallback_encoding)
|
return response_content.decode(response.encoding or fallback_encoding)
|
||||||
|
|
||||||
if soup:
|
if soup:
|
||||||
if content_type in SOUP_CONTENT_TYPES:
|
if not check_content_type or content_type in SOUP_CONTENT_TYPES:
|
||||||
soup = bs4.BeautifulSoup(_decode_data(), parser)
|
soup = bs4.BeautifulSoup(_decode_data(), parser)
|
||||||
return Response(response.status_code, soup, response_headers)
|
return Response(response.status_code, soup, response_headers)
|
||||||
else:
|
else:
|
||||||
raise HTTPWrongContentTypeException(
|
raise HTTPWrongContentTypeException(
|
||||||
"Tried to soup non-html/non-xml data")
|
"Tried to soup non-html/non-xml data (%s)" % content_type)
|
||||||
|
|
||||||
data = _decode_data()
|
data = _decode_data()
|
||||||
if json and data:
|
if json and data:
|
||||||
|
|
Loading…
Reference in a new issue