Exemplo n.º 1
0
    def send_body_chunks(self, DATA, code, msg=None, desc=None, ctype='text/xml"', headers={}):
        """ send a body in chunks """

        self.responses[207] = (msg, desc)
        self.send_response(code, message=msg)
        self.send_header("Content-type", ctype)
        self.send_header("Transfer-Encoding", "chunked")
        self.send_header("Date", rfc1123_date())

        self._send_dav_version()

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if "gzip" in self.headers.get("Accept-Encoding", "").split(",") and len(DATA) > self.encode_threshold:
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode="wb", fileobj=buffer)
                if isinstance(DATA, str):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header("Content-Encoding", "gzip")

            self.send_header("Content-Length", len(DATA))
            self.send_header("Content-Type", ctype)

        else:
            self.send_header("Content-Length", 0)

        self.end_headers()

        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                self.wfile.write(DATA)
                self.wfile.write("\r\n")
                self.wfile.write("0\r\n")
                self.wfile.write("\r\n")
            else:
                if self._config.DAV.getboolean("http_response_use_iterator"):
                    # Use iterator to reduce using memory
                    for buf in DATA:
                        self.wfile.write(hex(len(buf))[2:] + "\r\n")
                        self.wfile.write(buf)
                        self.wfile.write("\r\n")

                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
                else:
                    # Don't use iterator, it's a compatibility option
                    self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                    self.wfile.write(DATA.read())
                    self.wfile.write("\r\n")
                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
Exemplo n.º 2
0
    def send_body(self,
                  DATA,
                  code=None,
                  msg=None,
                  desc=None,
                  ctype='application/octet-stream',
                  headers={}):
        """ send a body in one part """
        log.debug("Use send_body method")

        print "KUBA:send_body:", code, msg, DATA

        self.send_response(code, message=msg)
        self.send_header("Connection", "close")
        self.send_header("Accept-Ranges", "bytes")
        self.send_header('Date', rfc1123_date())

        self._send_dav_version()

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if 'gzip' in self.headers.get('Accept-Encoding', '').split(',') \
                    and len(DATA) > self.encode_threshold:
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str) or isinstance(DATA, unicode):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            self.send_header('Content-Type', ctype)
        else:
            self.send_header('Content-Length', 0)

        self.end_headers()
        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                log.debug("Don't use iterator")
                self.wfile.write(DATA)
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    log.debug("Use iterator")
                    for buf in DATA:
                        self.wfile.write(buf)
                        self.wfile.flush()
                else:
                    # Don't use iterator, it's a compatibility option
                    log.debug("Don't use iterator")
                    self.wfile.write(DATA.read())
Exemplo n.º 3
0
    def send_body(self, DATA, code=None, msg=None, desc=None,
                  ctype='application/octet-stream', headers={}):
        """ send a body in one part """
        log.debug("Use send_body method")

        print "KUBA:send_body:",code,msg,DATA


        self.send_response(code, message=msg)
        self.send_header("Connection", "close")
        self.send_header("Accept-Ranges", "bytes")
        self.send_header('Date', rfc1123_date())

        self._send_dav_version()

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if 'gzip' in self.headers.get('Accept-Encoding', '').split(',') \
                    and len(DATA) > self.encode_threshold:
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str) or isinstance(DATA, unicode):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            self.send_header('Content-Type', ctype)
        else:
            self.send_header('Content-Length', 0)

        self.end_headers()
        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                log.debug("Don't use iterator")
                self.wfile.write(DATA)
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    log.debug("Use iterator")
                    for buf in DATA:
                        self.wfile.write(buf)
                        self.wfile.flush()
                else:
                    # Don't use iterator, it's a compatibility option
                    log.debug("Don't use iterator")
                    self.wfile.write(DATA.read())
Exemplo n.º 4
0
	def generate_headers(self):
		self.extra_headers["server"] = self.server_info
		self.extra_headers["date"] = rfc1123_date(datetime.utcnow())
		return super(HttpServerResponse, self).generate_headers()
Exemplo n.º 5
0
    def send_body_chunks(self,
                         DATA,
                         code,
                         msg=None,
                         desc=None,
                         ctype='application/xml"',
                         headers={}):
        """ send a body in chunks """

        print "KUBA:send_body_chunks:", code, msg, DATA

        self.responses[207] = (msg, desc)
        self.send_response(code, message=msg)
        self.send_header("Content-Type", ctype)
        self.send_header("Transfer-Encoding", "chunked")
        self.send_header('Date', rfc1123_date())

        self._send_dav_version()

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if ('gzip' in self.headers.get('Accept-Encoding', '').split(',')
                    and len(DATA) > self.encode_threshold):
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            #self.send_header('Content-Type', ctype) # this leads to duplicate Content-Type header which 1) is useless, 2) incorrect(?), 3) confuses the owncloud sync client

        else:
            self.send_header('Content-Length', 0)

        self.end_headers()

        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                self.wfile.write(DATA)
                self.wfile.write("\r\n")
                self.wfile.write("0\r\n")
                self.wfile.write("\r\n")
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    for buf in DATA:
                        self.wfile.write(hex(len(buf))[2:] + "\r\n")
                        self.wfile.write(buf)
                        self.wfile.write("\r\n")

                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
                else:
                    # Don't use iterator, it's a compatibility option
                    self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                    self.wfile.write(DATA.read())
                    self.wfile.write("\r\n")
                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
Exemplo n.º 6
0
    def send_body_chunks(self,
                         DATA,
                         code,
                         msg=None,
                         desc=None,
                         ctype='text/xml"',
                         headers={}):
        """ send a body in chunks """

        self.responses[207] = (msg, desc)
        self.send_response(code, message=msg)
        self.send_header("Content-type", ctype)
        self.send_header("Transfer-Encoding", "chunked")
        self.send_header('Date', rfc1123_date())
        self.send_header('DAV', DAV_VERSION_2['version'])

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if (('gzip' in self.headers.get('Accept-Encoding', '').split(','))
                    and (len(DATA) > self.encode_threshold)):
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            self.send_header('Content-Type', ctype)

        else:
            self.send_header('Content-Length', 0)

        self.end_headers()

        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                self._append(hex(len(DATA))[2:] + "\r\n")
                self._append(DATA)
                self._append("\r\n")
                self._append("0\r\n")
                self._append("\r\n")
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    self.wfile.write(self._buffer)
                    self.wfile.flush()
                    self._buffer = ""

                    for buf in DATA:
                        self.wfile.write(hex(len(buf))[2:] + "\r\n")
                        self.wfile.write(buf)
                        self.wfile.write("\r\n")

                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
                else:
                    # Don't use iterator, it's a compatibility option
                    self._append(hex(len(DATA))[2:] + "\r\n")
                    self._append(DATA.read())
                    self._append("\r\n")
                    self._append("0\r\n")
                    self._append("\r\n")
Exemplo n.º 7
0
 def generate_headers(self):
     self.extra_headers["server"] = self.server_info
     self.extra_headers["date"] = rfc1123_date(datetime.utcnow())
     return super(HttpServerResponse, self).generate_headers()
Exemplo n.º 8
0
    def send_body_chunks(self, DATA, code, msg=None, desc=None,
                            ctype='text/xml"', headers={}):
        """ send a body in chunks """

        self.responses[207] = (msg, desc)
        self.send_response(code, message=msg)
        self.send_header("Content-type", ctype)
        self.send_header("Transfer-Encoding", "chunked")
        self.send_header('Date', rfc1123_date())
        self.send_header('DAV', DAV_VERSION_2['version'])

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if (
                ('gzip' in self.headers.get('Accept-Encoding', '').split(',')) and
                (len(DATA) > self.encode_threshold)
            ):
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            self.send_header('Content-Type', ctype)

        else:
            self.send_header('Content-Length', 0)

        self.end_headers()

        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                self._append(hex(len(DATA))[2:] + "\r\n")
                self._append(DATA)
                self._append("\r\n")
                self._append("0\r\n")
                self._append("\r\n")
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    self.wfile.write(self._buffer)
                    self.wfile.flush()
                    self._buffer = ""

                    for buf in DATA:
                        self.wfile.write(hex(len(buf))[2:] + "\r\n")
                        self.wfile.write(buf)
                        self.wfile.write("\r\n")

                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
                else:
                    # Don't use iterator, it's a compatibility option
                    self._append(hex(len(DATA))[2:] + "\r\n")
                    self._append(DATA.read())
                    self._append("\r\n")
                    self._append("0\r\n")
                    self._append("\r\n")
Exemplo n.º 9
0
    def send_body_chunks(self, DATA, code, msg=None, desc=None,
                         ctype='application/xml"', headers={}):
        """ send a body in chunks """

        print "KUBA:send_body_chunks:",code,msg,DATA

        self.responses[207] = (msg, desc)
        self.send_response(code, message=msg)
        self.send_header("Content-Type", ctype)
        self.send_header("Transfer-Encoding", "chunked")
        self.send_header('Date', rfc1123_date())

        self._send_dav_version()

        for a, v in headers.items():
            self.send_header(a, v)

        if DATA:
            if ('gzip' in self.headers.get('Accept-Encoding', '').split(',')
                and len(DATA) > self.encode_threshold):
                buffer = StringIO.StringIO()
                output = gzip.GzipFile(mode='wb', fileobj=buffer)
                if isinstance(DATA, str):
                    output.write(DATA)
                else:
                    for buf in DATA:
                        output.write(buf)
                output.close()
                buffer.seek(0)
                DATA = buffer.getvalue()
                self.send_header('Content-Encoding', 'gzip')

            self.send_header('Content-Length', len(DATA))
            #self.send_header('Content-Type', ctype) # this leads to duplicate Content-Type header which 1) is useless, 2) incorrect(?), 3) confuses the owncloud sync client

        else:
            self.send_header('Content-Length', 0)

        self.end_headers()

        if DATA:
            if isinstance(DATA, str) or isinstance(DATA, unicode):
                self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                self.wfile.write(DATA)
                self.wfile.write("\r\n")
                self.wfile.write("0\r\n")
                self.wfile.write("\r\n")
            else:
                if self._config.DAV.getboolean('http_response_use_iterator'):
                    # Use iterator to reduce using memory
                    for buf in DATA:
                        self.wfile.write(hex(len(buf))[2:] + "\r\n")
                        self.wfile.write(buf)
                        self.wfile.write("\r\n")

                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")
                else:
                    # Don't use iterator, it's a compatibility option
                    self.wfile.write(hex(len(DATA))[2:] + "\r\n")
                    self.wfile.write(DATA.read())
                    self.wfile.write("\r\n")
                    self.wfile.write("0\r\n")
                    self.wfile.write("\r\n")