当前位置: 首页>>代码示例>>Python>>正文


Python HeaderKeyDict.setdefault方法代码示例

本文整理汇总了Python中swift.common.swob.HeaderKeyDict.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python HeaderKeyDict.setdefault方法的具体用法?Python HeaderKeyDict.setdefault怎么用?Python HeaderKeyDict.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.swob.HeaderKeyDict的用法示例。


在下文中一共展示了HeaderKeyDict.setdefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_request_headers

# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import setdefault [as 别名]
    def generate_request_headers(self, orig_req=None, additional=None,
                                 transfer=False):
        """
        Create a list of headers to be used in backend requets

        :param orig_req: the original request sent by the client to the proxy
        :param additional: additional headers to send to the backend
        :param transfer: If True, transfer headers from original client request
        :returns: a dictionary of headers
        """
        # Use the additional headers first so they don't overwrite the headers
        # we require.
        headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
        if transfer:
            self.transfer_headers(orig_req.headers, headers)
        headers.setdefault('x-timestamp', normalize_timestamp(time.time()))
        if orig_req:
            referer = orig_req.as_referer()
        else:
            referer = ''
        headers['x-trans-id'] = self.trans_id
        headers['connection'] = 'close'
        headers['user-agent'] = 'proxy-server %s' % os.getpid()
        headers['referer'] = referer
        return headers
开发者ID:sa4250mnpo70,项目名称:swift,代码行数:27,代码来源:base.py

示例2: generate_request_headers

# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import setdefault [as 别名]
    def generate_request_headers(self, orig_req=None, additional=None, transfer=False):
        """
        Create a list of headers to be used in backend requets

        :param orig_req: the original request sent by the client to the proxy
        :param additional: additional headers to send to the backend
        :param transfer: If True, transfer headers from original client request
        :returns: a dictionary of headers
        """
        # Use the additional headers first so they don't overwrite the headers
        # we require.
        headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
        if transfer:
            self.transfer_headers(orig_req.headers, headers)
        headers.setdefault("x-timestamp", normalize_timestamp(time.time()))
        if orig_req:
            referer = orig_req.as_referer()
        else:
            referer = ""
        headers.update(
            {
                "x-trans-id": self.trans_id,
                "connection": "close",
                "user-agent": "proxy-server %s" % os.getpid(),
                "referer": referer,
            }
        )
        return headers
开发者ID:niuzhenguo,项目名称:swift,代码行数:30,代码来源:base.py


注:本文中的swift.common.swob.HeaderKeyDict.setdefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。