Пример #1
0
    def __call__(self, out, buf):
        try:
            # read http message (response line + headers)
            try:
                raw_data = yield from buf.readuntil(
                    b'\r\n\r\n', self.max_line_size + self.max_headers)
            except errors.LineLimitExceededParserError as exc:
                raise errors.LineTooLong(exc.limit) from None

            lines = raw_data.decode('ascii',
                                    'surrogateescape').splitlines(True)

            line = lines[0]
            try:
                version, status = line.split(None, 1)
            except ValueError:
                raise errors.BadStatusLine(line) from None
            else:
                try:
                    status, reason = status.split(None, 1)
                except ValueError:
                    reason = ''

            # version
            match = VERSRE.match(version)
            if match is None:
                raise errors.BadStatusLine(line)
            version = (int(match.group(1)), int(match.group(2)))

            # The status code is a three-digit number
            try:
                status = int(status)
            except ValueError:
                raise errors.BadStatusLine(line) from None

            if status < 100 or status > 999:
                raise errors.BadStatusLine(line)

            # read headers
            headers, close, compression = self.parse_headers(lines)

            if close is None:
                close = version <= (1, 0)

            out.feed_data(
                RawResponseMessage(version, status, reason.strip(), headers,
                                   close, compression))
            out.feed_eof()
        except aiohttp.EofStream:
            # Presumably, the server closed the connection before
            # sending a valid response.
            raise errors.ClientConnectionError(
                'Can not read status line') from None
Пример #2
0
    def __call__(self, out, buf):
        # read http message (response line + headers)
        try:
            raw_data = yield from buf.readuntil(
                b'\r\n\r\n', self.max_line_size + self.max_headers)
        except errors.LineLimitExceededParserError as exc:
            raise errors.LineTooLong(exc.limit) from None

        lines = raw_data.decode('ascii', 'surrogateescape').split('\r\n')

        line = lines[0]
        try:
            version, status = line.split(None, 1)
        except ValueError:
            raise errors.BadStatusLine(line) from None
        else:
            try:
                status, reason = status.split(None, 1)
            except ValueError:
                reason = ''

        # version
        match = VERSRE.match(version)
        if match is None:
            raise errors.BadStatusLine(line)
        version = HttpVersion(int(match.group(1)), int(match.group(2)))

        # The status code is a three-digit number
        try:
            status = int(status)
        except ValueError:
            raise errors.BadStatusLine(line) from None

        if status < 100 or status > 999:
            raise errors.BadStatusLine(line)

        # read headers
        headers, close, compression = self.parse_headers(lines)

        if close is None:
            close = version <= HttpVersion10

        out.feed_data(
            RawResponseMessage(version, status, reason.strip(), headers, close,
                               compression))
        out.feed_eof()
Пример #3
0
    def __call__(self, out, buf):
        try:
            # read http message (request line + headers)
            raw_data = yield from buf.readuntil(b'\r\n\r\n', self.max_headers,
                                                errors.LineTooLong)
            lines = raw_data.decode('ascii',
                                    'surrogateescape').splitlines(True)

            # request line
            line = lines[0]
            try:
                method, path, version = line.split(None, 2)
            except ValueError:
                raise errors.BadStatusLine(line) from None

            # method
            method = method.upper()
            if not METHRE.match(method):
                raise errors.BadStatusLine(method)

            # version
            match = VERSRE.match(version)
            if match is None:
                raise errors.BadStatusLine(version)
            version = (int(match.group(1)), int(match.group(2)))

            # read headers
            headers, close, compression = self.parse_headers(lines)
            if version <= (1, 0):
                close = True
            elif close is None:
                close = False

            out.feed_data(
                RawRequestMessage(method, path, version, headers, close,
                                  compression))
            out.feed_eof()
        except aiohttp.EofStream:
            # Presumably, the server closed the connection before
            # sending a valid response.
            pass
Пример #4
0
    def __call__(self, out, buf):
        # read http message (request line + headers)
        try:
            raw_data = yield from buf.readuntil(b'\r\n\r\n', self.max_headers)
        except errors.LineLimitExceededParserError as exc:
            raise errors.LineTooLong(exc.limit) from None

        lines = raw_data.decode('ascii', 'surrogateescape').split('\r\n')

        # request line
        line = lines[0]
        try:
            method, path, version = line.split(None, 2)
        except ValueError:
            raise errors.BadStatusLine(line) from None

        # method
        method = method.upper()
        if not METHRE.match(method):
            raise errors.BadStatusLine(method)

        # version
        match = VERSRE.match(version)
        if match is None:
            raise errors.BadStatusLine(version)
        version = HttpVersion(int(match.group(1)), int(match.group(2)))

        # read headers
        headers, close, compression = self.parse_headers(lines)
        if version <= HttpVersion10:
            close = True
        elif close is None:
            close = False

        out.feed_data(
            RawRequestMessage(method, path, version, headers, close,
                              compression))
        out.feed_eof()
Пример #5
0
    def __call__(self, out, buf):
        raw_data = yield from buf.waituntil(b' ', 24)
        method = raw_data.decode('ascii', 'surrogateescape').strip()

        # method
        method = method.upper()
        if not METHRE.match(method):
            raise errors.BadStatusLine(method)

        # allowed method
        if self.allowed_methods and method not in self.allowed_methods:
            raise errors.HttpMethodNotAllowed(method)

        out.feed_data(method)
        out.feed_eof()
Пример #6
0
    def __call__(self, out, buf):
        try:
            raw_data = yield from buf.waituntil(b' ', 24)
            method = raw_data.decode('ascii', 'surrogateescape').strip()

            # method
            method = method.upper()
            if not METHRE.match(method):
                raise errors.BadStatusLine(method)

            # allowed method
            if self.allowed_methods and method not in self.allowed_methods:
                raise errors.HttpMethodNotAllowed(method)

            out.feed_data(method)
            out.feed_eof()
        except aiohttp.EofStream:
            # Presumably, the server closed the connection before
            # sending a valid response.
            pass