We really need a Proxy developing for use with advanced GIS layers
(MGRS data - being able to download high resolution PDFs suitable for
I have example CGI code & example Django code.
I really need a Web2Py controller :)
I can do the integration once the basic controller is done.
Seems like a nice task for someone?
To test make an app "proxy" with a controller "proxy.py" that
PROXY_USER = None
PROXY_PASSWORD = None
PROXY_URL = 'web2py.com:80'
path = '/'+'/'.join(request.args)
query = request.env.query_string
method = request.env.request_method
if PROXY_USER and PROXY_PASSWORD:
conn = httplib.HTTPConnection(PROXY_URL)
if method == 'GET':
conn.request(method, path, query)
elif method == 'POST':
data = request.body.read()
conn.request(method, path, data)
res = conn.getresponse()
content = res.read()
headers = dict(res.getheaders())
response.headers['Content-Type'] = headers['content-type']
response.status = int(res.status)
and the following routes.py
routes_in = [('/examples/$anything',
This will proxy http://web2py.com for urls startinsg with /
Checking it out now...
Well, thanks anyway :)
Seems like this doesn't really do what we wanted anyway...this allows
us to proxy requests via a proxy server.
What we wanted was an actual proxy server.
I must have read the Django app's docs wrong!
Luckily we have a working port of the CGI version...currently very
basic, but we can build on it :)
On Jan 23, 6:45 pm, Fran <francisb...@googlemail.com> wrote:
I was confused by this technique at first.
The __call__ function of the Cache global class instance, cache, is
shown used as a decorator on page 113 of the web2py manual (2nd ed).
@cache cannot be used before def proxy since the use of a cache is
conditional on what the request method is (namely GET).
The above usage is just an alternative that modifiies the already
defined proxy function on a per request basis.
More confusion busting that is going off topic and should be placed in
a topic of its own that discusses style issues.
For those who are not adjusted to the 'web2py way', the above mention
of 'global class instance' might appear incorrect, impossible or at
the least, 'not the Python way', since no import is implied or
suggested. Globals, as conventionally understood, are frowned upon by
the Python hierarchy, much to the annoyance of those from just about
every other programming environment who work with involved projects. C/
C++ programmers can conventionally tuck away a global namespace with
preprocessor #include statements and files. Python equivalents are not
as straightforward since an import always involves executing a file
(the first time an import on a file is used).
Web2py favours exec over import. The global class instance, cache, is
placed in a dictionary that becomes the environment during an exec.
The line 'environment['cache'] = Cache(request)' appears in the file
Hence there is no import.
Ultimately this style leads to more elegance and productivity and
leads to less bugs. How much time is wasted wondering what has been
forgotten to import when coding with Django and irritating compile
The above snippet seems to proxy internal content rather than fetch
external content like the Django example.
> > can have multiple controllers toproxydifferent servers. Similarly to
whoops, the Django snippet also does this.