示例#1
0
def SSLProxyFetch(request, proto, resource):
    """
    I have been called with /secure/some/url.stuff

    - My primary duty is to listen on a url, and fetch and return the requested
      file.
    - My secondary duty is to make sure that the file in question is
      whitelisted...  I'm not exposing a blind web proxy!

    But on a production server, I will be listening on SSL and thus provide it.
    """

    myURL = proto + '://' + resource

    try:
        WhiteListedURLs.objects.get(allowed_url = myURL)
    except WhiteListedURLs.DoesNotExist:
        return HttpResponseForbidden(_('Requested Resource Denied'))

    try:
        spf = sessionlessProxyFetch(myURL)
    except:
        # Probably needs a debug flag to raise or log this.
        return HttpResponseServerError(_('Unknown problem proxying Resource'))

    headers = spf.info().headers
    headers_d = dict(
        [i.strip().split(': ') for i in headers]
    )

    if 'Content-Type' in headers_d:
        response = HttpResponse(mimetype=headers_d['Content-Type'])
    else:
        response = HttpResponse()

    data = spf.read()
    response.write(data)
    return response
示例#2
0
 def fetch(self):
     return sessionlessProxyFetch(self.allowed_url)