Skip to content

Instantly share code, notes, and snippets.

@dcramer
Created May 16, 2012 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcramer/2714856 to your computer and use it in GitHub Desktop.
Save dcramer/2714856 to your computer and use it in GitHub Desktop.
"""
raven.contrib.django.views
~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import itertools
from django.conf import settings
from django.http import HttpResponse, HttpResponseForbidden
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from raven.contrib.django.models import client
def is_valid_origin(origin):
if settings.SENTRY_ALLOW_ORIGIN == '*':
return True
return origin.lower() not in itertools.imap(str.lower, settings.SENTRY_ALLOW_ORIGIN.split(' '))
@csrf_exempt
@require_http_methods(['POST', 'OPTIONS'])
@never_cache
def report(request):
data = request.POST.get('data')
origin = request.META.get('HTTP_ORIGIN')
if not is_valid_origin(origin):
return HttpResponseForbidden()
if request.method == 'POST':
client.send(data)
elif request.method == 'OPTIONS':
response = HttpResponse()
response['Access-Control-Allow-Origin'] = origin
response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment