depot.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def __set_response_expires(self, op_name, expires, max_age=None):
                """Used to set expiration headers on a response dynamically
                based on the name of the operation.

                'op_name' is a string containing the name of the depot
                operation as listed in the REPO_OPS_* constants.

                'expires' is an integer value in seconds indicating how
                long from when the request was made the content returned
                should expire.  The maximum value is 365*86400.

                'max_age' is an integer value in seconds indicating the
                maximum length of time a response should be considered
                valid.  For some operations, the maximum value for this
                parameter is equal to the repository's refresh_seconds
                property."""

                prefix = self._get_req_pub()
                if not prefix:
                        prefix = self.repo.cfg.get_property("publisher",
                            "prefix")

                rs = None
                if prefix:
                        try:
                                pub = self.repo.get_publisher(prefix)
                        except Exception as e:
                                # Couldn't get pub.
                                pass
                        else:
                                repo = pub.repository
                                if repo:
                                        rs = repo.refresh_seconds
                if rs is None:
                        rs = 14400

                if max_age is None:
                        max_age = min((rs, expires))

                now = cherrypy.response.time
                if op_name == "publisher" or op_name == "search" or \
                    op_name == "catalog":
                        # For these operations, cap the value based on
                        # refresh_seconds.
                        expires = now + min((rs, max_age))
                        max_age = min((rs, max_age))
                else:
                        expires = now + expires

                headers = cherrypy.response.headers
                headers["Cache-Control"] = \
                    "must-revalidate, no-transform, max-age={0:d}".format(
                        max_age)
                headers["Expires"] = formatdate(timeval=expires, usegmt=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号