Add a test for the data URI handler now taking the body into account

This commit is contained in:
Adrián Chaves 2022-06-30 17:42:51 +02:00
parent 7ef061fc17
commit 3d7e2e5021
1 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import os
import shutil
import sys
import tempfile
from base64 import b64encode
from typing import Optional, Type
from unittest import mock
@ -1237,3 +1238,15 @@ class DataURITestCase(unittest.TestCase):
request = Request("data:,")
return self.download_request(request, self.spider).addCallback(_test)
def test_body_mime_type(self):
"""Test that the body, and not only the declared MIME type, is taken
into account when choosing a response class."""
def _test(response):
self.assertIsInstance(response, HtmlResponse)
html = '<!DOCTYPE html>\n<title>.</title>'
base64_html = b64encode(html.encode()).decode()
data_uri = f'data:application/unknown;base64,{base64_html}'
request = Request(data_uri)
return self.download_request(request, self.spider).addCallback(_test)