Пример #1
0
    def handle_encoding(self, headers, fd):
        http_object = Framework.PyFlagMap("HTTP/%s" % fd.readptr,
                                          base=fd.urn.value)
        try:
            try:
                skip = int(headers['content-length'])
                http_object.write_from(fd.urn, fd.tell(), skip)
                fd.seek(skip, 1)

                return http_object.urn
            except KeyError:
                pass

            ## If no content-length is specified maybe its chunked
            try:
                if "chunked" in headers['transfer-encoding'].lower():
                    while True:
                        line = fd.readline()
                        try:
                            length = int(line, 16)
                        except:
                            return http_object.urn

                        if length == 0:
                            return http_object.urn

                        ## There is a \r\n delimiter after the data chunk
                        http_object.write_from(fd.urn, fd.tell(), length)
                        fd.seek(length + 2, 1)
                    return http_object.urn
            except KeyError:
                pass

            ## If the header says close then the rest of the file is the
            ## body (all data until connection is closed)
            try:
                if "close" in headers['connection'].lower():
                    http_object.write_from(fd.urn, fd.tell(),
                                           fd.size.value - fd.tell())
            except KeyError:
                pass

            return http_object.urn
        finally:
            http_object.cache_return()
Пример #2
0
 def make_stream(self, name, base, navigatable=True):
     return Framework.PyFlagMap(name, base=base, navigatable=navigatable)