Exemple #1
0
    def get(self):
        all_items = context.application.cache.items()[::-1]
        req_list = []
        for item in all_items:
            info = dict(
                id=item['id'],
                size=item['size'],
                duration=item['duration'],
                start_time=item['start_time'],
                request=dict(url=item['request'].get('url'),
                             path=item['request'].get('path'),
                             host=item['request'].get('host'),
                             method=item['request'].get('method')),
                response=dict(
                    code=item['response']['code'],
                    mock=item['response']['headers'].get('lyrebird', 'proxy'),
                    modified=item['request']['headers'].get(
                        'lyrebird_modified') or
                    item['response']['headers'].get('lyrebird_modified', ''))
                if item.get('response') else {})
            # Add key `proxy_response` into info only if item contains proxy_response
            if item.get('proxy_response'):
                info['proxy_response'] = {
                    'code': item['proxy_response']['code']
                }
            req_list.append(info)

        def gen():
            yield json.dumps(req_list, ensure_ascii=False)

        return context.make_streamed_response(gen)
Exemple #2
0
    def get(self):
        all_items = context.application.cache.items()[::-1]
        req_list = []
        for item in all_items:
            info = dict(id=item['id'],
                        size=item['size'],
                        duration=item['duration'],
                        request=dict(url=item['request'].get('url'),
                                     path=item['request'].get('path'),
                                     host=item['request'].get('host')),
                        response=dict(code=item['response']['code'],
                                      mock=item['response']['headers'].get(
                                          'lyrebird', 'proxy'))
                        if item.get('response') else {})
            req_list.append(info)

        def gen():
            yield json.dumps(req_list)

        return context.make_streamed_response(gen)