Пример #1
0
    def close(self):
        self.closed = True
        if hasattr(self._iterator, 'close'):
            self._iterator.close()

        if self.headers_set:
            status_code, headers = self.headers_set
            bytes_sent = sum(self.chunks)
            content_length = headers.get('content-length', type=int)

            if status_code == 304:
                for key, value in headers:
                    key = key.lower()
                    if key not in ('expires', 'content-location') and \
                       is_entity_header(key):
                        warn(HTTPWarning('entity header %r found in 304 '
                            'response' % key))
                if bytes_sent:
                    warn(HTTPWarning('304 responses must not have a body'))
            elif 100 <= status_code < 200 or status_code == 204:
                if content_length != 0:
                    warn(HTTPWarning('%r responses must have an empty '
                                     'content length') % status_code)
                if bytes_sent:
                    warn(HTTPWarning('%r responses must not have a body' %
                                     status_code))
            elif content_length is not None and content_length != bytes_sent:
                warn(WSGIWarning('Content-Length and the number of bytes '
                                 'sent to the client do not match.'))
Пример #2
0
    def close(self):
        self.closed = True
        if hasattr(self._iterator, 'close'):
            self._iterator.close()

        if self.headers_set:
            status_code, headers = self.headers_set
            bytes_sent = sum(self.chunks)
            content_length = headers.get('content-length', type=int)

            if status_code == 304:
                for key, value in headers:
                    key = key.lower()
                    if key not in ('expires', 'content-location') and \
                       is_entity_header(key):
                        warn(
                            HTTPWarning('entity header %r found in 304 '
                                        'response' % key))
                if bytes_sent:
                    warn(HTTPWarning('304 responses must not have a body'))
            elif 100 <= status_code < 200 or status_code == 204:
                if content_length != 0:
                    warn(
                        HTTPWarning('%r responses must have an empty '
                                    'content length' % status_code))
                if bytes_sent:
                    warn(
                        HTTPWarning('%r responses must not have a body' %
                                    status_code))
            elif content_length is not None and content_length != bytes_sent:
                warn(
                    WSGIWarning('Content-Length and the number of bytes '
                                'sent to the client do not match.'))
Пример #3
0
    def close(self):
        self.closed = True
        if hasattr(self._iterator, "close"):
            self._iterator.close()

        if self.headers_set:
            status_code, headers = self.headers_set
            bytes_sent = sum(self.chunks)
            content_length = headers.get("content-length", type=int)

            if status_code == 304:
                for key, value in headers:
                    key = key.lower()
                    if key not in ("expires", "content-location") and is_entity_header(key):
                        warn(HTTPWarning("entity header %r found in 304 " "response" % key))
                if bytes_sent:
                    warn(HTTPWarning("304 responses must not have a body"))
            elif 100 <= status_code < 200 or status_code == 204:
                if content_length != 0:
                    warn(HTTPWarning("%r responses must have an empty " "content length") % status_code)
                if bytes_sent:
                    warn(HTTPWarning("%r responses must not have a body" % status_code))
            elif content_length is not None and content_length != bytes_sent:
                warn(WSGIWarning("Content-Length and the number of bytes " "sent to the client do not match."))