From Seeks
# Copyright Camille Harang
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.fsf.org/licensing/licenses/agpl-3.0.html.
import urllib
from urlparse import urljoin
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect
[...]
def seeks(request, path):
if path == '': return HttpResponseRedirect('websearch-hp')
public_url = urljoin(settings.ROOT_URL, settings.SEEKS_PATH)
local_url = urljoin(settings.SEEKS_URI, path)
if 'QUERY_STRING' in request.META and request.META['QUERY_STRING']:
local_url = '%s?%s' % (local_url, request.META['QUERY_STRING'])
opener = urllib.urlopen(local_url, proxies={'http': settings.SEEKS_PROXY})
info = opener.info()
mime = ''
if 'content-type' in info: mime = info['content-type'].split(';')[0]
else: mime = ''
content = opener.read()
if mime.startswith('text/') and mime != 'text/javascript':
content = content.replace(settings.SEEKS_URI, public_url)
content = content.replace('"/', '"%s' % public_url)
content = content.replace("'/", "'%s" % public_url)
content = content.replace('url(/', 'url(%s' % public_url)
return HttpResponse(content, mimetype=mime)