示例#1
0
    def frombytes(cls, byte_string):
        """
        Parse an AWS request from a byte string.

        @param byte_string: The request as parsed from a C{.req} file.
        @type byte_string: L{bytes}

        @return: A request object.
        @rtype: L{_AWSRequest}
        """
        # Ensure there's a blank line so that status and header
        # parsing completes.
        blank_line = b'\n\n'
        if blank_line not in byte_string:
            byte_string += blank_line

        channel = HTTPChannel()
        channel.delimiter = b'\n'
        channel.makeConnection(StringTransport())
        channel.dataReceived(byte_string)
        channel.connectionLost(ConnectionDone())
        request = channel.requests[-1]

        method = request.method
        path = request.uri
        headers = dict(request.requestHeaders.getAllRawHeaders())
        # what comes after the empty line is a
        body = byte_string.split(blank_line, 1)[-1]

        return cls(method, path, headers, body)