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


Python Response.headers[header]方法代码示例

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


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

示例1: relay

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers[header] [as 别名]
 def relay(self, req):
     """Relay a request to a remote machine for JS proxying"""
     host = req.GET['host']
     conn = httplib.HTTPConnection(host)
     headers = req.headers
     
     # Re-assemble the query string
     query_str = {}
     for param, val in req.GET.iteritems():
         if param in ['host', 'path']: continue
         query_str[param] = val
     query_str = urllib.urlencode(query_str)
     
     # Transport a GET or a POST
     if req.method == 'GET':
         conn.request("GET", '%s?%s' % (req.GET['path'], query_str), headers=headers)
     elif req.method == 'POST':
         conn.request("POST", req.GET['path'], req.body, headers=headers)
     
     # Handle the response and pull out the headers to proxy back
     resp = conn.getresponse()
     res = Response()
     for header, value in resp.getheaders():
         if header.lower() in ['server', 'date']: continue
         res.headers[header] = value
     res.body = resp.read()
     return res
开发者ID:adrianpike,项目名称:wwscc,代码行数:29,代码来源:evalexception.py

示例2: post_traceback

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers[header] [as 别名]
 def post_traceback(self, req):
     """Post the long XML traceback to the host and path provided"""
     debug_info = req.debug_info
     long_xml_er = formatter.format_xml(debug_info.exc_data, 
         show_hidden_frames=True, show_extra_data=False, 
         libraries=self.libraries)[0]
     host = req.GET['host']
     headers = req.headers
     conn = httplib.HTTPConnection(host)
     headers = {'Content-Length':len(long_xml_er), 
                'Content-Type':'application/xml'}
     conn.request("POST", req.GET['path'], long_xml_er, headers=headers)
     resp = conn.getresponse()
     res = Response()
     for header, value in resp.getheaders():
         if header.lower() in ['server', 'date']: continue
         res.headers[header] = value
     res.body = resp.read()
     return res
开发者ID:adrianpike,项目名称:wwscc,代码行数:21,代码来源:evalexception.py

示例3: handle_request

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers[header] [as 别名]
    def handle_request(self, env, req):
        if req.method not in ('GET', 'HEAD'):
            headers = self._getCacheHeaders(CACHE_BAD_URL)
            return HTTPMethodNotAllowed(request=req, headers=headers)
        # allow earlier middleware to override hash and obj_name
        hsh = env.get('swift.cdn_hash')
        object_name = env.get('swift.cdn_object_name')
        if not (hsh and object_name):
            for regex in self.cdn_regexes:
                match_obj = regex.match(req.url)
                if match_obj:
                    match_dict = match_obj.groupdict()
                    hsh = match_dict.get('cdn_hash')
                    object_name = match_dict.get('object_name')
                    break

        if not (hsh and object_name):
            headers = self._getCacheHeaders(CACHE_BAD_URL)
            return HTTPNotFound(request=req, headers=headers)
        cdn_obj_path = self._get_hsh_obj_path(hsh)
        hash_data = self._get_cdn_data(env, cdn_obj_path)
        if hash_data and hash_data.cdn_enabled:
            # this is a cdn enabled container, proxy req to swift
            swift_path = '/v1/%s/%s/%s' % (hash_data.account,
                                           hash_data.container, object_name)
            headers = self._getCdnHeaders(req)
            resp = make_pre_authed_request(env, req.method, swift_path,
                headers=headers, agent='SwiftOrigin').get_response(self.app)
            if resp.status_int == 304:
                return resp
            # we don't have to worry about the 401 case
            if resp.status_int == 404:
                return HTTPNotFound(request=req,
                    headers=self._getCacheHeaders(CACHE_404))
            if resp.status_int == 416:
                return HTTPRequestRangeNotSatisfiable(request=req,
                    headers=self._getCacheHeaders(CACHE_404))
            if resp.status_int in (200, 206):
                #TODO: not doing the check for content-length == None ok?
                if resp.content_length > self.max_cdn_file_size:
                    return HTTPBadRequest(request=req,
                        headers=self._getCacheHeaders(CACHE_404))
                cdn_resp = Response(request=req, app_iter=resp.app_iter)
                cdn_resp.status = resp.status_int
                cdn_resp.last_modified = resp.last_modified
                cdn_resp.etag = resp.etag
                cdn_resp.content_length = resp.content_length
                for header in ('Content-Range', 'Content-Encoding',
                               'Content-Disposition', 'Accept-Ranges',
                               'Content-Type'):
                    header_val = resp.headers.get(header)
                    if header_val:
                        cdn_resp.headers[header] = header_val

                cdn_resp.headers.update(self._getCacheHeaders(hash_data.ttl))

                return cdn_resp
            self.logger.exception('Unexpected response from Swift: %s, %s' %
                                  (resp.status, cdn_obj_path))
        return HTTPNotFound(request=req,
                            headers=self._getCacheHeaders(CACHE_404))
开发者ID:smballe,项目名称:sos,代码行数:63,代码来源:origin.py


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