def get_data_from_request(self, request): result = {} user = getattr(request, 'user', None) if user is not None: user_info = self.get_user_info(user) if user_info: result['user'] = user_info try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: if isinstance(data, MultiValueDict): data = dict( (k, v[0] if len(v) == 1 else v) for k, v in iterlists(data)) else: data = None environ = request.META result.update({ 'request': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result
def get_data_from_request(self, request): result = {} user = getattr(request, 'user', None) if user is not None: user_info = self.get_user_info(user) if user_info: result['user'] = user_info try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: if isinstance(data, MultiValueDict): data = dict( (k, v[0] if len(v) == 1 else v) for k, v in iterlists(data)) else: data = None environ = request.META result.update({ 'request': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result