Beispiel #1
0
def get_data_from_request(request):
    urlparts = _urlparse.urlsplit(request.url)

    try:
        formdata = request.form
    except ClientDisconnected:
        formdata = {}

    data = {
        'sentry.interfaces.Http': {
            'url':
            '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
    }
    try:
        user_data = get_user_info(request)
    except Exception as e:
        logger.exception(e)
    else:
        if user_data:
            data['sentry.interfaces.User'] = user_data

    return data
Beispiel #2
0
def get_data_from_request(request):
    try:
        from flask.globals import _request_ctx_stack
    except ImportError:
        pass
    else:
        if not _request_ctx_stack.top:
            return {}

    urlparts = _urlparse.urlsplit(request.url)

    try:
        formdata = request.form
    except ClientDisconnected:
        formdata = {}

    data = {
        'sentry.interfaces.Http': {
            'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
    }
    try:
        user_data = get_user_info(request)
    except Exception as e:
        logger.exception(e)
    else:
        if user_data:
            data['sentry.interfaces.User'] = user_data

    return data
Beispiel #3
0
def get_request_info(request):
    '''
    Returns context data extracted from :param:`request`.

    Heavily based on flask integration for Sentry: https://git.io/vP4i9.
    '''
    urlparts = _urlparse.urlsplit(request.url)
    return {
        'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
        'query_string': urlparts.query,
        'method': request.method,
        'headers': dict(get_headers(request.environ)),
        'env': dict(get_environ(request.environ)),
    }
Beispiel #4
0
def get_request_info(request):
    '''
    Returns context data extracted from :param:`request`.

    Heavily based on flask integration for Sentry: https://git.io/vP4i9.
    '''
    urlparts = _urlparse.urlsplit(request.url)
    return {
        'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
        'query_string': urlparts.query,
        'method': request.method,
        'headers': dict(get_headers(request.environ)),
        'env': dict(get_environ(request.environ)),
    }
Beispiel #5
0
    def get_http_info_with_retriever(self, request, retriever = None):
        if retriever is None:
            retriever = self.get_form_data
        urlparts = _urlparse.urlsplit(request.url)
        try:
            data = retriever(request)
        except ClientDisconnected:
            data = {}

        return {'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
         'query_string': urlparts.query,
         'method': request.method,
         'data': data,
         'headers': dict(get_headers(request.environ)),
         'env': dict(get_environ(request.environ))}
Beispiel #6
0
def get_data_from_request(request):
    urlparts = _urlparse.urlsplit(request.url)
    try:
        form_dict = request.forms.dict
        formdata = dict([ (k, form_dict[k][-1]) for k in form_dict ])
    except Exception:
        formdata = {}

    data = {'request': {'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
                 'query_string': urlparts.query,
                 'method': request.method,
                 'data': formdata,
                 'headers': dict(get_headers(request.environ)),
                 'env': dict(get_environ(request.environ))}}
    return data
Beispiel #7
0
    def get_http_info(self, request):
        urlparts = _urlparse.urlsplit(request.url)

        try:
            formdata = request.form
        except ClientDisconnected:
            formdata = {}

        return {
            "url": "%s://%s%s" % (urlparts.scheme, urlparts.netloc, urlparts.path),
            "query_string": urlparts.query,
            "method": request.method,
            "data": formdata,
            "headers": dict(get_headers(request.environ)),
            "env": dict(get_environ(request.environ)),
        }
Beispiel #8
0
    def get_http_info(self, request):
        urlparts = _urlparse.urlsplit(request.url)

        try:
            formdata = request.form
        except ClientDisconnected:
            formdata = {}

        return {
            'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
Beispiel #9
0
    def get_http_info(self, request):
        urlparts = _urlparse.urlsplit(request.url)

        try:
            formdata = request.form
        except ClientDisconnected:
            formdata = {}

        return {
            'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
Beispiel #10
0
    def get_http_info_with_retriever(self, request, retriever=None):
        """
        Exact method for getting http_info but with form data work around.
        """
        urlparts = _urlparse.urlsplit(request.url)

        try:
            data = retriever(request)
        except (ClientDisconnected, TypeError):
            data = {}

        return {
            "url": "%s://%s%s" % (urlparts.scheme, urlparts.netloc, urlparts.path),
            "query_string": urlparts.query,
            "method": request.method,
            "data": data,
            "headers": dict(get_headers(request.environ)),
            "env": dict(get_environ(request.environ)),
        }
Beispiel #11
0
def get_data_from_request(request):
    urlparts = _urlparse.urlsplit(request.url)

    try:
        form_dict = request.forms.dict
        # we only are about the most recent one
        formdata = dict([(k, form_dict[k][-1]) for k in form_dict])
    except Exception:
        formdata = {}

    data = {
        'sentry.interfaces.Http': {
            'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
    }

    return data
Beispiel #12
0
    def get_http_info_with_retriever(self, request, retriever=None):
        """
        Exact method for getting http_info but with form data work around.
        """
        if retriever is None:
            retriever = self.get_form_data

        urlparts = _urlparse.urlsplit(request.url)

        try:
            data = retriever(request)
        except ClientDisconnected:
            data = {}

        return {
            'url': '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': data,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
Beispiel #13
0
def get_data_from_request(request):
    urlparts = _urlparse.urlsplit(request.url)

    try:
        form_dict = request.forms.dict
        # we only are about the most recent one
        formdata = dict([(k, form_dict[k][-1]) for k in form_dict])
    except Exception:
        formdata = {}

    data = {
        'sentry.interfaces.Http': {
            'url':
            '%s://%s%s' % (urlparts.scheme, urlparts.netloc, urlparts.path),
            'query_string': urlparts.query,
            'method': request.method,
            'data': formdata,
            'headers': dict(get_headers(request.environ)),
            'env': dict(get_environ(request.environ)),
        }
    }

    return data