[docs]classHTTP(HTTPBase[Data_HTTP,Schema_HTTP],data=Data_HTTP,schema=Schema_HTTP):"""This class implements Hypertext Transfer Protocol (HTTP/1.*)."""########################################################################### Defaults.###########################################################################: Type: Type of HTTP receipt._receipt:'Type'########################################################################### Properties.##########################################################################@propertydefalias(self)->'Literal["HTTP/0.9", "HTTP/1.0", "HTTP/1.1"]':"""Acronym of current protocol."""returnf'HTTP/{self.version}'# type: ignore[return-value]@propertydefversion(self)->'Literal["0.9", "1.0", "1.1"]':"""Version of current protocol."""returnself._info.receipt.version# type: ignore[attr-defined]########################################################################### Methods.##########################################################################
[docs]defread(self,length:'Optional[int]'=None,**kwargs:'Any')->'Data_HTTP':# pylint: disable=unused-argument"""Read Hypertext Transfer Protocol (HTTP/1.*). Structure of HTTP/1.* packet [:rfc:`7230`]: .. code-block:: text HTTP-message :==: start-line *( header-field CRLF ) CRLF [ message-body ] Args: length: Length of packet data. **kwargs: Arbitrary keyword arguments. Returns: Parsed packet data. Raises: ProtocolError: If the packet is malformed. """iflengthisNone:length=len(self)schema=self.__header__packet=schema.dataheader,body=packet.split(b'\r\n\r\n',maxsplit=1)header_line,header_unpacked=self._read_http_header(header)body_unpacked=self._read_http_body(body,headers=header_unpacked)orNonehttp=Data_HTTP(receipt=header_line,header=header_unpacked,body=body_unpacked,)self._receipt=header_line.typeself._version=header_line.version# type: ignore[attr-defined]self._length=len(header)returnhttp
[docs]@classmethoddefid(cls)->'tuple[Literal["HTTP"], Literal["HTTPv1"]]':# type: ignore[override]"""Index ID of the protocol. Returns: Index ID of the protocol. """return(cls.__name__,'HTTPv1')# type: ignore[return-value]