Hi, Thanks for the reply! This looks neat. Although, right now I would rather not depend on two additional packages if I can :\
I think I'll settle with copying a few headers manually for now: def digitalObject(request, id): import base64 import urllib2 url="http://some.url.com/somefile" req = urllib2.Request(url) resp = urllib2.urlopen(req) objfile = resp.read() response["Expires"] = resp.info().getheader("Expires") response["Content-Disposition"] = resp.info().getheader("Content- Disposition") response["Date"] = resp.info().getheader("Date") response["Content-Type"] = resp.info().getheader("Content-Type") return response Filipe On May 6, 3:35 pm, Gustavo Narea <gna...@tech.2degreesnetwork.com> wrote: > You could do it quite easily with twod.wsgi and Paste: > > """ > from paste.proxy import Proxy > from twod.wsgi import make_wsgi_view > > class ProxyRemoteFile(Proxy): > def __call__(self, environ, start_response): > environ['PATH_INFO'] = "/fixed/path/to/file" > return super(ProxyRemoteFile, self).__call__(environ, > start_response) > > proxy_app = ProxyRemoteFile("some.url.com", ["GET"]) > > # This is the Django view that you can attach to any URLConf: > proxy_view = make_wsgi_view(proxy_app) > """ > > More info > here:http://packages.python.org/twod.wsgi/http://pythonpaste.org/modules/proxy.html > > On May 6, 2:34 pm, Filipe Correia <fcorr...@gmail.com> wrote: > > > > > > > Hello everyone, > > > I'm trying to make a django-view that proxies the contents of a file > > from another URL. > > > This mostly works (I realize some error handling is still needed): > > > def digitalObject(request, id): > > import base64 > > import urllib2 > > url="http://some.url.com/somefile" > > req = urllib2.Request(url) > > resp = urllib2.urlopen(req) > > objfile = resp.read() > > response = HttpResponse(objfile) > > return response > > > but I'd like to avoid copying one by one the header elements of the > > original response (resp) to the HttpResponse (response). I mean, > > elements like, the mimetype, the Content-Disposition, etc. > > Is there a better way to convert a urlib2 response to a django one? > > > Thanks, > > Filipe > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.