Created
January 26, 2011 15:12
-
-
Save krikulis/796811 to your computer and use it in GitHub Desktop.
Django IFrame session Safari FIX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpRequest | |
# Safari default security policy restricts cookie setting in first request in iframe | |
# Solution is to create hidden form to preserve GET variables and REPOST it to current URL | |
class IFrameFixMiddleware(object): | |
""" middleware fixes sessions with Safari browser in iframes """ | |
def process_request(request): | |
if request.META['HTTP_USER_AGENT'].find('Safari') != -1 and 'sessionid' not in request.COOKIES and 'cookie_fix' not in request.GET: | |
html = """<html><body><form name='cookie_fix' method='GET' action='.'>""" | |
for item in request.GET: | |
html += "<input type='hidden' value='%s' name='%s' />" % (request.GET[name], name) | |
html += "<input type='hidden' name='cookie_fix' value='1' />" | |
html += "</form>" | |
html += '''<script type="text/javascript">document.cookie_fix.submit()</script></html>''' | |
return HttpResponse(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment