|
11 | 11 | import http.server
|
12 | 12 | import itertools
|
13 | 13 | import re
|
| 14 | +import string |
14 | 15 | import sys
|
15 | 16 | import zlib
|
16 | 17 | from wsgiref.handlers import format_date_time
|
|
20 | 21 | from aiohttp import multidict
|
21 | 22 | from aiohttp.log import internal_log
|
22 | 23 |
|
| 24 | +ASCIISET = set(string.printable) |
23 | 25 | METHRE = re.compile('[A-Z0-9$-_.]+')
|
24 | 26 | VERSRE = re.compile('HTTP/(\d+).(\d+)')
|
25 | 27 | HDRRE = re.compile('[\x00-\x1F\x7F()<>@,;:\[\]={} \t\\\\\"]')
|
@@ -572,8 +574,12 @@ def add_header(self, name, value):
|
572 | 574 | """Analyze headers. Calculate content length,
|
573 | 575 | removes hop headers, etc."""
|
574 | 576 | assert not self.headers_sent, 'headers have been sent already'
|
575 |
| - assert isinstance(name, str), '{!r} is not a string'.format(name) |
576 |
| - assert isinstance(value, str), '{!r} is not a string'.format(value) |
| 577 | + assert isinstance(name, str), \ |
| 578 | + 'Header name should be a string, got {!r}'.format(name) |
| 579 | + assert set(name).issubset(ASCIISET), \ |
| 580 | + 'Header name should contain ASCII chars, got {!r}'.format(name) |
| 581 | + assert isinstance(value, str), \ |
| 582 | + 'Header {!r} should have string value, got {!r}'.format(name, value) |
577 | 583 |
|
578 | 584 | name = name.strip().upper()
|
579 | 585 | value = value.strip()
|
|
0 commit comments