Ejemplo n.º 1
0
    def __call__(self, request):
        # Request
        request.time_begin = xtime.now()
        request_post = request.POST or request.body

        # 接收到请求
        if isinstance(request_post, dict):
            request_post = json.dumps(protect_dict_or_list(request_post),
                                      indent=2,
                                      sort_keys=True,
                                      ensure_ascii=False)
        logger.info(
            'response_accept',
            extra={
                'uri':
                f'{request.scheme}://{request.get_host()}{request.get_full_path()}',
                'remote_ip': request.META.get('REMOTE_ADDR'),
                'authorization': request.META.get('HTTP_AUTHORIZATION'),
                # postman 需要传入 header 参数为 internal-token(去掉前面的 HTTP- 并且使用减号代替下划线)
                'internal_token': request.META.get('HTTP_INTERNAL_TOKEN'),
                'method': request.method,
                'data': request_post,
            })
        request.do_request = Session()
        response = self.get_response(request)
        # 返回请求的日志在 shortcuts.py 中
        return response
Ejemplo n.º 2
0
 def test_request_id_passthrough(self):
     with self.settings(LOG_REQUEST_ID_HEADER='REQUEST_ID_HEADER'):
         request = self.factory.get('/')
         request.META['REQUEST_ID_HEADER'] = 'some_request_id'
         middleware = RequestIDMiddleware()
         middleware.process_request(request)
         self.assertEqual(request.id, 'some_request_id')
         session = Session()
         outgoing = Request('get', 'http://nowhere')
         session.prepare_request(outgoing)
         self.assertEqual(outgoing.headers['REQUEST_ID_HEADER'],
                          'some_request_id')
Ejemplo n.º 3
0
def get_block_quota_of_user(user):
    logger = module_logger.getChild('get_block_quota_of_user')
    logger.info('Retrieving quota of user %r on %r', user.username,
                settings.BLOCK_URL)
    response = Session().get(BASE_URL + 'quota/',
                             headers={
                                 'Authorization':
                                 'Token %s' %
                                 create_token(TokenModel, user, None),
                             })
    check_response(response, logger)
    quota = response.json()
    logger.info('Received quota: %r', quota)
    return quota['quota'], quota['size']
Ejemplo n.º 4
0
 def inner():
     from log_request_id.session import Session  # noqa
     Session()
Ejemplo n.º 5
0
 def inner():
     Session()