Exemple #1
0
    def make_object_response(self, req, metadata, stream=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        resp.headers['Content-Type'] = metadata.get(
            'mime-type', 'application/octet-stream')
        for k, v in metadata.iteritems():
            if k.startswith("user."):
                meta = k[5:]
                if is_sys_or_user_meta('object', meta) or \
                                meta.lower() in self.allowed_headers:
                    resp.headers[meta] = v
        resp.etag = metadata['hash'].lower()
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            resp.app_iter = stream
        resp.content_length = int(metadata['length'])
        try:
            resp.content_encoding = metadata['encoding']
        except KeyError:
            pass
        return resp
Exemple #2
0
    def make_object_response(self, req, metadata, stream=None, ranges=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req,
                        conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.iteritems():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        resp.headers['etag'] = metadata['hash'].lower()
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            if ranges:
                resp.app_iter = StreamRangeIterator(stream)
            else:
                resp.app_iter = stream

        resp.content_length = int(metadata['length'])
        try:
            resp.content_encoding = metadata['encoding']
        except KeyError:
            pass
        resp.accept_ranges = 'bytes'
        return resp
Exemple #3
0
    def make_object_response(self, req, metadata, stream=None, ranges=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.iteritems():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        resp.headers['etag'] = metadata['hash'].lower()
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            if ranges:
                resp.app_iter = StreamRangeIterator(stream)
            else:
                resp.app_iter = stream

        resp.content_length = int(metadata['length'])
        try:
            resp.content_encoding = metadata['encoding']
        except KeyError:
            pass
        resp.accept_ranges = 'bytes'
        return resp
Exemple #4
0
 def pass_file(self, req, path, content_type=None):
     """ pass a file to client """
     resp = Response()
     if content_type:
         resp.content_type = content_type
     else:
         (ctype, enc) = guess_type(basename(path))
         resp.content_type = ctype
     resp.charset = None
     try:
         with open(join(self.path, path)) as f:
             resp.app_iter = iter(f.read())
             return resp
     except IOError:
         return HTTPNotFound(request=req)
Exemple #5
0
 def pass_file(self, req, path, content_type=None):
     """ pass a file to client """
     resp = Response()
     if content_type:
         resp.content_type = content_type
     else:
         (ctype, enc) = guess_type(basename(path))
         resp.content_type = ctype
     resp.charset = None
     try:
         with open(join(self.path, path)) as f:
             resp.app_iter = iter(f.read())
             return resp
     except IOError:
         return HTTPNotFound(request=req)
Exemple #6
0
 def get_working_response(self, req):
     source, node = self._get_source_and_node()
     res = None
     if source:
         res = Response(request=req)
         if req.method == "GET" and source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
             res.app_iter = self._make_app_iter(node, source)
             # See NOTE: swift_conn at top of file about this.
             res.swift_conn = source.swift_conn
         res.status = source.status
         update_headers(res, source.getheaders())
         if not res.environ:
             res.environ = {}
         res.environ["swift_x_timestamp"] = source.getheader("x-timestamp")
         res.accept_ranges = "bytes"
         res.content_length = source.getheader("Content-Length")
         if source.getheader("Content-Type"):
             res.charset = None
             res.content_type = source.getheader("Content-Type")
     return res
Exemple #7
0
    def make_object_response(self, req, metadata, stream=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req,
                        conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.items():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        hash_ = metadata.get('hash')
        if hash_ is not None:
            hash_ = hash_.lower()
        resp.headers['etag'] = hash_
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        resp.last_modified = int(metadata['mtime'])
        if stream:
            # Whether we are bothered with ranges or not, we wrap the
            # stream in order to handle exceptions.
            resp.app_iter = StreamRangeIterator(req, stream)

        length_ = metadata.get('length')
        if length_ is not None:
            length_ = int(length_)
        resp.content_length = length_
        resp.content_encoding = metadata.get('encoding')
        resp.accept_ranges = 'bytes'
        return resp
Exemple #8
0
    def make_object_response(self, req, metadata, stream=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.iteritems():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        hash_ = metadata.get('hash')
        if hash_ is not None:
            hash_ = hash_.lower()
        resp.headers['etag'] = hash_
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            # Whether we are bothered with ranges or not, we wrap the
            # stream in order to handle exceptions.
            resp.app_iter = StreamRangeIterator(req, stream)

        length_ = metadata.get('length')
        if length_ is not None:
            length_ = int(length_)
        resp.content_length = length_
        resp.content_encoding = metadata.get('encoding')
        resp.accept_ranges = 'bytes'
        return resp
Exemple #9
0
 def get_working_response(self, req):
     source, node = self._get_source_and_node()
     res = None
     if source:
         res = Response(request=req)
         if req.method == 'GET' and \
                 source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
             res.app_iter = self._make_app_iter(node, source)
             # See NOTE: swift_conn at top of file about this.
             res.swift_conn = source.swift_conn
         res.status = source.status
         update_headers(res, source.getheaders())
         if not res.environ:
             res.environ = {}
         res.environ['swift_x_timestamp'] = \
             source.getheader('x-timestamp')
         res.accept_ranges = 'bytes'
         res.content_length = source.getheader('Content-Length')
         if source.getheader('Content-Type'):
             res.charset = None
             res.content_type = source.getheader('Content-Type')
     return res
Exemple #10
0
    def __call__(self, env, start_response):
        self.calls += 1
        if "swift.authorize" in env:
            resp = env["swift.authorize"](Request(env))
            if resp:
                return resp(env, start_response)
        if env["PATH_INFO"] == "/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1":
            return Response(status="412 Precondition Failed")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c1":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2/one.txt":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            """,
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b/index.html":
            resp = Response(status="204 No Content")
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/index.html":
            return Response(status="200 Ok", body="index file")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4":
            self.get_c4_called = True
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/one.txt":
            return Response(status="200 Ok", headers={"x-object-meta-test": "value"}, body="1")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/two.txt":
            return Response(status="503 Service Unavailable")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/404error.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/index.html":
            return Response(status="503 Service Unavailable")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/503error.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/404error.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c6":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c6b":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c6/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c6/401error.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Hey, you're not authorized to see this!</p>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c7", "/v1/a/c7/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c7/404error.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c7/401error.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Hey, you're not authorized to see this!</p>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c8", "/v1/a/c8/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c8/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c9", "/v1/a/c9/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c9/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c10", "/v1/a/c10/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c10/\xe2\x98\x83/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c11", "/v1/a/c11/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h2>c11 subdir index</h2>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir2/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir2/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c11a", "/v1/a/c11a/"):
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir/":
            return Response(status="200 Ok", headers={"Content-Type": "text/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir2/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir2/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir3/":
            return Response(status="200 Ok", headers={"Content-Type": "not_a/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir3/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c12/index.html":
            return Response(status="200 Ok", body="index file")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c12/200error.html":
            return Response(status="200 Ok", body="error file")(env, start_response)
        else:
            raise Exception("Unknown path %r" % env["PATH_INFO"])
Exemple #11
0
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(
                        self, lcontainer, listing, resp,
                        is_slo=(large_object == 'SLO'))

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    try:
                        content_length = sum(o['bytes'] for o in listing)
                        last_modified = \
                            max(o['last_modified'] for o in listing)
                        last_modified = datetime(*map(int, re.split('[^\d]',
                                                 last_modified)[:-1]))
                        etag = md5(
                            ''.join(o['hash'] for o in listing)).hexdigest()
Exemple #12
0
    def GETorHEAD_base(self, req, server_type, partition, nodes, path, attempts):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param partition: partition
        :param nodes: nodes
        :param path: path for the request
        :param attempts: number of attempts to try
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        sources = []
        newest = config_true_value(req.headers.get("x-newest", "f"))
        nodes = iter(nodes)
        while len(statuses) < attempts:
            try:
                node = nodes.next()
            except StopIteration:
                break
            if self.error_limited(node):
                continue
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    headers = dict(req.headers)
                    headers["Connection"] = "close"
                    conn = http_connect(
                        node["ip"],
                        node["port"],
                        node["device"],
                        partition,
                        req.method,
                        path,
                        headers=headers,
                        query_string=req.query_string,
                    )
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _("Trying to %(method)s %(path)s") % {"method": req.method, "path": req.path}
                )
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader("X-PUT-Timestamp", 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append("")
                    bodies.append("")
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append("")
                    sources.append(possible_source)
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node)
                elif is_server_error(possible_source.status):
                    self.error_occurred(
                        node,
                        _("ERROR %(status)d %(body)s " "From %(type)s Server")
                        % {"status": possible_source.status, "body": bodies[-1][:1024], "type": server_type},
                    )
        if sources:
            sources.sort(key=source_key)
            source = sources.pop()
            for src in sources:
                self.close_swift_conn(src)
            res = Response(request=req, conditional_response=True)
            if req.method == "GET" and source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ["swift_x_timestamp"] = source.getheader("x-timestamp")
            res.accept_ranges = "bytes"
            res.content_length = source.getheader("Content-Length")
            if source.getheader("Content-Type"):
                res.charset = None
                res.content_type = source.getheader("Content-Type")
            return res
        return self.best_response(req, statuses, reasons, bodies, "%s %s" % (server_type, req.method))
Exemple #13
0
                if req.method == 'HEAD':
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(self, lcontainer,
                                                      listing, resp)

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    content_length = sum(o['bytes'] for o in listing)
                    last_modified = max(o['last_modified'] for o in listing)
                    last_modified = datetime(
                        *map(int,
                             re.split('[^\d]', last_modified)[:-1]))
                    etag = md5(''.join(o['hash'] for o in listing)).hexdigest()
                else:
                    content_length = 0
                    last_modified = resp.last_modified
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(
                status='412 Precondition Failed')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok', body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                headers={'x-object-meta-test': 'value'},
                body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok', body='''
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/index.html':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/503error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/404error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c7', '/v1/a/c7/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c8', '/v1/a/c8/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c8/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c9', '/v1/a/c9/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c9/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c10', '/v1/a/c10/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c10/\xe2\x98\x83/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c11', '/v1/a/c11/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir/':
            return Response(status='200 Ok', headers={'Content-Type':\
                            'application/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir/index.html':
            return Response(status='200 Ok', body='''
<html>
    <body>
        <h2>c11 subdir index</h2>
    </body>
</html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir2/':
            return Response(status='200 Ok', headers={'Content-Type':\
                            'application/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir2/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c11a', '/v1/a/c11a/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir/':
            return Response(status='200 Ok', headers={'Content-Type':\
                            'text/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/':
            return Response(status='200 Ok', headers={'Content-Type':\
                            'application/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/':
            return Response(status='200 Ok', headers={'Content-Type':\
                            'not_a/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/index.html':
            return Response(status='404 Not Found')(env, start_response)
        else:
            raise Exception('Unknown path %r' % env['PATH_INFO'])
Exemple #15
0
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(
                        self, lcontainer, listing, resp,
                        is_slo=(large_object == 'SLO'))

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    try:
                        content_length = sum(o['bytes'] for o in listing)
                        last_modified = \
                            max(o['last_modified'] for o in listing)
                        last_modified = datetime(*map(int, re.split('[^\d]',
                                                 last_modified)[:-1]))
                        etag = md5(
                            ''.join(o['hash'] for o in listing)).hexdigest()
Exemple #16
0
                 secure=self.secure)
 resp.app_iter = tmpl({
     'ptype': 'containers',
     'title': self.title,
     'lang': lang,
     'top': self.page_path,
     'account': acc,
     'message': msg,
     'base': base,
     'whole_containers': whole_cont_list,
     'containers': cont_list,
     'container_meta': cont_meta,
     'container_acl': cont_acl,
     'containers_unquote': cont_unquote_name,
     'delete_confirm': delete_confirm,
     'acl_edit': acl_edit,
     'meta_edit': meta_edit,
     'enable_versions': self.enable_versions,
     'containers_version': cont_version_cont,
     'enable_container_sync': self.enable_container_sync,
     'contsync_edit': contsync_edit,
     'cont_sync_to': cont_sync_to,
     'cont_sync_key': cont_sync_key,
     'limit': limit,
     'prev_p': prev_marker,
     'next_p': next_marker,
     'last_p': last_marker,
     'delimiter': '',
     'prefix': ''
 })
 self.token_bank[token].update({'msg': ''})
Exemple #17
0
                if req.method == 'HEAD':
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(
                        self, lcontainer, listing, resp)

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    content_length = sum(o['bytes'] for o in listing)
                    last_modified = max(o['last_modified'] for o in listing)
                    last_modified = datetime(*map(int, re.split('[^\d]',
                                             last_modified)[:-1]))
                    etag = md5(
                        ''.join(o['hash'] for o in listing)).hexdigest()
                else:
                    content_length = 0
                    last_modified = resp.last_modified
Exemple #18
0
    def GETorHEAD_base(self, req, server_type, ring, partition, path):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param ring: the ring to obtain nodes from
        :param partition: partition
        :param path: path for the request
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        source_headers = []
        sources = []
        newest = config_true_value(req.headers.get('x-newest', 'f'))
        headers = self.generate_request_headers(req, additional=req.headers)
        for node in self.iter_nodes(ring, partition):
            start_node_timing = time.time()
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    conn = http_connect(
                        node['ip'], node['port'], node['device'], partition,
                        req.method, path, headers=headers,
                        query_string=req.query_string)
                self.app.set_node_timing(node, time.time() - start_node_timing)
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _('Trying to %(method)s %(path)s') %
                    {'method': req.method, 'path': req.path})
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader('X-PUT-Timestamp', 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append('')
                    bodies.append('')
                    source_headers.append('')
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append('')
                    source_headers.append('')
                    sources.append((possible_source, node))
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                source_headers.append(possible_source.getheaders())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node, _('ERROR Insufficient Storage'))
                elif is_server_error(possible_source.status):
                    self.error_occurred(node, _('ERROR %(status)d %(body)s '
                                                'From %(type)s Server') %
                                        {'status': possible_source.status,
                                         'body': bodies[-1][:1024],
                                         'type': server_type})
        res = None
        if sources:
            sources.sort(key=lambda s: source_key(s[0]))
            source, node = sources.pop()
            for src, _junk in sources:
                self.close_swift_conn(src)
            res = Response(request=req)
            if req.method == 'GET' and \
                    source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ['swift_x_timestamp'] = \
                source.getheader('x-timestamp')
            res.accept_ranges = 'bytes'
            res.content_length = source.getheader('Content-Length')
            if source.getheader('Content-Type'):
                res.charset = None
                res.content_type = source.getheader('Content-Type')
        if not res:
            res = self.best_response(req, statuses, reasons, bodies,
                                     '%s %s' % (server_type, req.method),
                                     headers=source_headers)
        try:
            (account, container) = split_path(req.path_info, 1, 2)
            _set_info_cache(self.app, req.environ, account, container, res)
        except ValueError:
            pass
        try:
            (account, container, obj) = split_path(req.path_info, 3, 3, True)
            _set_object_info_cache(self.app, req.environ, account,
                                   container, obj, res)
        except ValueError:
            pass
        return res
Exemple #19
0
    def GETorHEAD_base(self, req, server_type, ring, partition, path):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param ring: the ring to obtain nodes from
        :param partition: partition
        :param path: path for the request
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        sources = []
        newest = config_true_value(req.headers.get('x-newest', 'f'))
        for node in self.iter_nodes(ring, partition):
            start_node_timing = time.time()
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    headers = dict(req.headers)
                    headers['Connection'] = 'close'
                    conn = http_connect(node['ip'],
                                        node['port'],
                                        node['device'],
                                        partition,
                                        req.method,
                                        path,
                                        headers=headers,
                                        query_string=req.query_string)
                self.app.set_node_timing(node, time.time() - start_node_timing)
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type,
                    _('Trying to %(method)s %(path)s') % {
                        'method': req.method,
                        'path': req.path
                    })
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader('X-PUT-Timestamp', 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append('')
                    bodies.append('')
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append('')
                    sources.append((possible_source, node))
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node, _('ERROR Insufficient Storage'))
                elif is_server_error(possible_source.status):
                    self.error_occurred(
                        node,
                        _('ERROR %(status)d %(body)s '
                          'From %(type)s Server') % {
                              'status': possible_source.status,
                              'body': bodies[-1][:1024],
                              'type': server_type
                          })
        if sources:
            sources.sort(key=lambda s: source_key(s[0]))
            source, node = sources.pop()
            for src, _junk in sources:
                self.close_swift_conn(src)
            res = Response(request=req, conditional_response=True)
            if req.method == 'GET' and \
                    source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ['swift_x_timestamp'] = \
                source.getheader('x-timestamp')
            res.accept_ranges = 'bytes'
            res.content_length = source.getheader('Content-Length')
            if source.getheader('Content-Type'):
                res.charset = None
                res.content_type = source.getheader('Content-Type')
            return res
        return self.best_response(req, statuses, reasons, bodies,
                                  '%s %s' % (server_type, req.method))
Exemple #20
0
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(
                status='412 Precondition Failed')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*'})
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-index': 'index.html',
                                 'x-container-meta-web-listings': 't'})
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok', body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-index': 'index.html',
                                 'x-container-meta-web-listings': 't'})
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-index': 'index.html',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': 'listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                headers={'x-object-meta-test': 'value'},
                body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok', body='''
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    <body>
<html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-index': 'index.html',
                                 'x-container-meta-listings': 't',
                                 'x-container-meta-web-error': 'error.html'})
        elif env['PATH_INFO'] == '/v1/a/c5/index.html':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/503error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/404error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-listings': 't'})
        elif env['PATH_INFO'] == '/v1/a/c6/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c7', '/v1/a/c7/'):
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-listings': 'f'})
        elif env['PATH_INFO'] in ('/v1/a/c8', '/v1/a/c8/'):
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': \
                               'http://localhost/stylesheets/listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c8/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c9', '/v1/a/c9/'):
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': \
                               '/absolute/listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c9/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        else:
            raise Exception('Unknown path %r' % env['PATH_INFO'])
Exemple #21
0
    def GETorHEAD_base(self, req, server_type, partition, nodes, path,
                       attempts):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param partition: partition
        :param nodes: nodes
        :param path: path for the request
        :param attempts: number of attempts to try
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        sources = []
        newest = config_true_value(req.headers.get('x-newest', 'f'))
        nodes = iter(nodes)
        while len(statuses) < attempts:
            try:
                node = nodes.next()
            except StopIteration:
                break
            if self.error_limited(node):
                continue
            start_node_timing = time.time()
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    headers = dict(req.headers)
                    headers['Connection'] = 'close'
                    conn = http_connect(
                        node['ip'], node['port'], node['device'], partition,
                        req.method, path, headers=headers,
                        query_string=req.query_string)
                self.app.set_node_timing(node, time.time() - start_node_timing)
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _('Trying to %(method)s %(path)s') %
                    {'method': req.method, 'path': req.path})
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader('X-PUT-Timestamp', 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append('')
                    bodies.append('')
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append('')
                    sources.append(possible_source)
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node)
                elif is_server_error(possible_source.status):
                    self.error_occurred(node, _('ERROR %(status)d %(body)s '
                                                'From %(type)s Server') %
                                        {'status': possible_source.status,
                                         'body': bodies[-1][:1024],
                                         'type': server_type})
        if sources:
            sources.sort(key=source_key)
            source = sources.pop()
            for src in sources:
                self.close_swift_conn(src)
            res = Response(request=req, conditional_response=True)
            if req.method == 'GET' and \
                    source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ['swift_x_timestamp'] = \
                source.getheader('x-timestamp')
            res.accept_ranges = 'bytes'
            res.content_length = source.getheader('Content-Length')
            if source.getheader('Content-Type'):
                res.charset = None
                res.content_type = source.getheader('Content-Type')
            return res
        return self.best_response(req, statuses, reasons, bodies,
                                  '%s %s' % (server_type, req.method))
Exemple #22
0
    def __call__(self, env, start_response):
        self.calls += 1
        if env["PATH_INFO"] == "/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1":
            return Response(status="412 Precondition Failed")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c1":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2":
            return self.listing(env, start_response, {"x-container-read": ".r:*"})
        elif env["PATH_INFO"] == "/v1/a/c2/one.txt":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3":
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-listings": "t",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c3/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            """,
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b":
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-listings": "t",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c3b/index.html":
            resp = Response(status="204 No Content")
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/index.html":
            return Response(status="200 Ok", body="index file")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4":
            self.get_c4_called = True
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-error": "error.html",
                    "x-container-meta-web-listings": "t",
                    "x-container-meta-web-listings-css": "listing.css",
                    "x-container-meta-web-directory-type": "text/dir",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c4/one.txt":
            return Response(status="200 Ok", headers={"x-object-meta-test": "value"}, body="1")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/two.txt":
            return Response(status="503 Service Unavailable")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/404error.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5":
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-listings": "t",
                    "x-container-meta-web-error": "error.html",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c5/index.html":
            return Response(status="503 Service Unavailable")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/503error.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5/404error.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c6":
            return self.listing(env, start_response, {"x-container-read": ".r:*", "x-container-meta-web-listings": "t"})
        elif env["PATH_INFO"] == "/v1/a/c6/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c7", "/v1/a/c7/"):
            return self.listing(env, start_response, {"x-container-read": ".r:*", "x-container-meta-web-listings": "f"})
        elif env["PATH_INFO"] in ("/v1/a/c8", "/v1/a/c8/"):
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-error": "error.html",
                    "x-container-meta-web-listings": "t",
                    "x-container-meta-web-listings-css": "http://localhost/stylesheets/listing.css",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c8/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c9", "/v1/a/c9/"):
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-error": "error.html",
                    "x-container-meta-web-listings": "t",
                    "x-container-meta-web-listings-css": "/absolute/listing.css",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c9/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c10", "/v1/a/c10/"):
            return self.listing(env, start_response, {"x-container-read": ".r:*", "x-container-meta-web-listings": "t"})
        elif env["PATH_INFO"] == "/v1/a/c10/\xe2\x98\x83/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c11", "/v1/a/c11/"):
            return self.listing(
                env, start_response, {"x-container-read": ".r:*", "x-container-meta-web-index": "index.html"}
            )
        elif env["PATH_INFO"] == "/v1/a/c11/subdir/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h2>c11 subdir index</h2>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir2/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11/subdir2/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] in ("/v1/a/c11a", "/v1/a/c11a/"):
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-directory-type": "text/directory",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir/":
            return Response(status="200 Ok", headers={"Content-Type": "text/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir2/":
            return Response(status="200 Ok", headers={"Content-Type": "application/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir2/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir3/":
            return Response(status="200 Ok", headers={"Content-Type": "not_a/directory"})(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c11a/subdir3/index.html":
            return Response(status="404 Not Found")(env, start_response)
        else:
            raise Exception("Unknown path %r" % env["PATH_INFO"])
Exemple #23
0
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(status='412 Precondition Failed')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*'})
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(
                env, start_response, {
                    'x-container-read': '.r:*',
                    'x-container-meta-web-index': 'index.html',
                    'x-container-meta-web-listings': 't'
                })
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok',
                            body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(
                env, start_response, {
                    'x-container-read': '.r:*',
                    'x-container-meta-web-index': 'index.html',
                    'x-container-meta-web-listings': 't'
                })
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(
                env, start_response, {
                    'x-container-read': '.r:*',
                    'x-container-meta-web-index': 'index.html',
                    'x-container-meta-web-error': 'error.html',
                    'x-container-meta-web-listings': 't',
                    'x-container-meta-web-listings-css': 'listing.css'
                })
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                            headers={'x-object-meta-test': 'value'},
                            body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok',
                            body='''
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    <body>
<html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5':
            return self.listing(
                env, start_response, {
                    'x-container-read': '.r:*',
                    'x-container-meta-web-index': 'index.html',
                    'x-container-meta-listings': 't',
                    'x-container-meta-web-error': 'error.html'
                })
        elif env['PATH_INFO'] == '/v1/a/c5/index.html':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/503error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/404error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6':
            return self.listing(env, start_response, {
                'x-container-read': '.r:*',
                'x-container-meta-web-listings': 't'
            })
        elif env['PATH_INFO'] == '/v1/a/c6/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c7', '/v1/a/c7/'):
            return self.listing(env, start_response, {
                'x-container-read': '.r:*',
                'x-container-meta-web-listings': 'f'
            })
        elif env['PATH_INFO'] in ('/v1/a/c8', '/v1/a/c8/'):
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': \
                               'http://localhost/stylesheets/listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c8/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c9', '/v1/a/c9/'):
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': \
                               '/absolute/listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c9/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        else:
            raise Exception('Unknown path %r' % env['PATH_INFO'])
Exemple #24
0
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(status='412 Precondition Failed')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok',
                            body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                            headers={'x-object-meta-test': 'value'},
                            body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok',
                            body='''
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/index.html':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/503error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/404error.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c6/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c7', '/v1/a/c7/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c8', '/v1/a/c8/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c8/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c9', '/v1/a/c9/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c9/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c10', '/v1/a/c10/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c10/\xe2\x98\x83/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c11', '/v1/a/c11/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir/':
            return Response(status='200 Ok',
                            headers={'Content-Type':
                                     'application/directory'})(env,
                                                               start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir/index.html':
            return Response(status='200 Ok',
                            body='''
<html>
    <body>
        <h2>c11 subdir index</h2>
    </body>
</html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir2/':
            return Response(status='200 Ok',
                            headers={'Content-Type':
                                     'application/directory'})(env,
                                                               start_response)
        elif env['PATH_INFO'] == '/v1/a/c11/subdir2/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] in ('/v1/a/c11a', '/v1/a/c11a/'):
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir/':
            return Response(status='200 Ok',
                            headers={'Content-Type':
                                     'text/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/':
            return Response(status='200 Ok',
                            headers={'Content-Type':
                                     'application/directory'})(env,
                                                               start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/':
            return Response(status='200 Ok',
                            headers={'Content-Type':
                                     'not_a/directory'})(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c12/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c12/200error.html':
            return Response(status='200 Ok', body='error file')(env,
                                                                start_response)
        else:
            raise Exception('Unknown path %r' % env['PATH_INFO'])
Exemple #25
0
                 max_age=self.cookie_max_age,
                 secure=self.secure)
 resp.app_iter = tmpl({'ptype': 'containers',
                       'title': self.title,
                       'lang': lang,
                       'top': self.page_path,
                       'account': acc,
                       'message': msg,
                       'base': base,
                       'whole_containers': whole_cont_list,
                       'containers': cont_list,
                       'container_meta': cont_meta,
                       'container_acl': cont_acl,
                       'containers_unquote': cont_unquote_name,
                       'delete_confirm': delete_confirm,
                       'acl_edit': acl_edit,
                       'meta_edit': meta_edit,
                       'enable_versions': self.enable_versions,
                       'containers_version': cont_version_cont,
                       'enable_container_sync': self.enable_container_sync,
                       'contsync_edit': contsync_edit,
                       'cont_sync_to': cont_sync_to,
                       'cont_sync_key': cont_sync_key,
                       'limit': limit,
                       'prev_p': prev_marker,
                       'next_p': next_marker,
                       'last_p': last_marker,
                       'delimiter': '',
                       'prefix': ''})
 self.token_bank[token].update({'msg': ''})
 self.memcache_update(token)