Exemple #1
0
    def render_GET(self, request, bodyless=False):
        """GET returns contents of a blob"""
        # process path and extract potential containers/fnm
        _, __, fullpath = parse_path(request.path)
        log.msg("Getting blob (non-cdmi) %s" % fullpath)
        tre_header = request.getHeader('tre-enabled')
        tre_request = tre_header is not None and tre_header.lower() == 'true'
        # perform operation on ADT
        status, vals = blob.read(self.avatar, fullpath, tre_request)
        # construct response
        request.setResponseCode(status)
        set_common_headers(request, False)
        if tre_request and status == FOUND:
            request.setHeader('Location', "/".join([c('general', 'tre_server'),
                                                    str(vals['uid'])]))

        if status is OK:
            # XXX: hack - some-why the response just hangs if to simply path
            # mimetype as a content_object type
            mimetype = vals['mimetype']
            actual_type = 'text/plain' if mimetype == 'text/plain' else str(mimetype)
            request.setHeader('Content-Type', actual_type)
            request.setLastModified(float(vals['mtime']))
            if not bodyless:
                request.setHeader('Content-Length', str(vals['size']))
                producer = self.makeProducer(request, vals['content'])
                producer.start()
                return NOT_DONE_YET
            else:
                return ''
        return ''
Exemple #2
0
    def render_GET(self, request, bodyless=False):
        """GET operation corresponds to reading of the blob object"""
        # process path and extract potential containers/fnm
        _, __, fullpath = parse_path(request.path)

        tre_header = request.getHeader('tre-enabled')
        tre_request = tre_header is not None and tre_header.lower() == 'true'
        log.msg("Request for TRE-enabled download received.")
        # perform operation on ADT
        status, vals = blob.read(self.avatar, fullpath, tre_request)
        # construct response
        request.setResponseCode(status)

        request.setHeader('Content-Type', CDMI_OBJECT)
        if tre_request and status == FOUND:
            request.setHeader('Location', "/".join([c('general', 'tre_server'),
                                                    str(vals['uid'])]))
            request.setLastModified(float(vals['mtime']))

        set_common_headers(request)
        if status == OK:
            request.setLastModified(float(vals['mtime']))
            if not bodyless:
                valueencoding = vals['valuetransferencoding']
                # for content we want to read in the full object into memory
                content = (vals['content'].read() if valueencoding == 'utf-8' else
                          base64.b64encode(vals['content'].read()))

                # construct body
                response_body = {
                                 'completionStatus': 'Complete',
                                 'mimetype': vals['mimetype'],
                                 'metadata': vals['metadata'],
                                 'valuetransferencoding': valueencoding,
                                 'value': content,
                                 'actual_uri': vals.get('actual_uri'),
                                 'capabilitiesURI': '/cdmi_capabilities/dataobject'
                                 }
                response_body.update(get_common_body(request, str(vals['uid']),
                                                     fullpath))
                return json.dumps(response_body)
        return ''