Commits

Gael Pasgrimaud  committed 6483a0c

allow get via proxy

  • Participants
  • Parent commits e4d93ed
  • Tags 0.7

Comments (0)

Files changed (3)

File saladedefruits/salade.py

 # -*- coding: utf-8 -*-
-from utils import Request
+from restkit.ext.wsgi_proxy import HostProxy
+from utils import Request, Response
+import urlparse
 
 def join(base, *parts):
     if not base.endswith('/'):
         req.remove_conditional_headers()
         if url.startswith('/'):
             req.path_info = url
-            resp = req.get_response(self.config['application'])
+            app = self.config['application']
         else:
-            resp = Response()
+            req.scheme, req.host, req.path_info, d, req.query_string, d = urlparse.urlparse(url)
+            app = HostProxy(req.host_url, allowed_methods=['GET'])
+        resp = req.get_response(app)
         if resp.content_type.startswith('text/html') and resp.status.startswith('200'):
             return resp
-        return None
+        return Response()
 
     def __call__(self):
         """main method. you need to surclass this and apply your own rules. Default is:

File saladedefruits/saladier.py

 # -*- coding: utf-8 -*-
-import os
-import urlparse
+from restkit.ext.wsgi_proxy import HostProxy
 from utils import Request, Response
+from paste.fileapp import FileApp
+from webob.dec import wsgify
 from pyquery import PyQuery
 from salade import Salade
-from paste.fileapp import FileApp
-from webob.dec import wsgify
+import urlparse
+import os
 
 
 class Saladier(object):
 
     def get(self, url):
         """get an html page from the app or an url"""
+        req = Request.blank(url)
         if url.startswith('/'):
-            req = Request.blank(url)
-            resp = req.get_response(self.application)
+            app = self.application
         else:
-            resp = Response()
+            app = HostProxy(req.host_url, allowed_methods=['GET'])
+        resp = req.get_response(app)
         if resp.content_type.startswith('text/html') and resp.status.startswith('200'):
             return resp
-        return None
+        return Response()
 
     @wsgify(RequestClass=Request)
     def __call__(self, req):

File saladedefruits/tests/tests.py

         resp = self.get('/user.html')
         self.theme('#content').prepend(resp.doc('#user_infos'))
         self.rewrite_links()
+        resp = self.get('http://www.google.com')
         return self.theme
 
 class Tests(unittest.TestCase):