Skip to content
Myr

utils.py

This file

Path

http3/utils.py

31 lines · 784 bytes · Python

Last changed by

http3 (#86)Tom Christiebefore adoptionc9747aa

History of this file

Take it

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 1–31why, one step back
1import codecs
2import typing345def normalize_header_key(value: typing.AnyStr, encoding: str = None) -> bytes:6 """7 Coerce str/bytes into a strictly byte-wise HTTP header key.8 """9 if isinstance(value, bytes):10 return value.lower()11 return value.encode(encoding or "ascii").lower()121314def normalize_header_value(value: typing.AnyStr, encoding: str = None) -> bytes:15 """16 Coerce str/bytes into a strictly byte-wise HTTP header value.17 """18 if isinstance(value, bytes):19 return value20 return value.encode(encoding or "ascii")212223def is_known_encoding(encoding: str) -> bool:24 """25 Return `True` if `encoding` is a known codec.26 """27 try:28 codecs.lookup(encoding)29 except LookupError:30 return False31 return True