Haiti: Proxy required - Django port? CGI port?

22 views
Skip to first unread message

Fran

unread,
Jan 23, 2010, 12:01:27 PM1/23/10
to web2py-users
Hullo again :)

We really need a Proxy developing for use with advanced GIS layers
(MGRS data - being able to download high resolution PDFs suitable for
ground operations)

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?

http://trac.sahanapy.org/wiki/BluePrintGISProxy

:D

mdipierro

unread,
Jan 23, 2010, 2:24:15 PM1/23/10
to web2py-users
Here is your proxy port of he Django one but without the httplib2
dependency).

To test make an app "proxy" with a controller "proxy.py" that
contains:

import httplib
PROXY_USER = None
PROXY_PASSWORD = None
PROXY_URL = 'web2py.com:80'

def proxy():
path = '/'+'/'.join(request.args)
query = request.env.query_string
method = request.env.request_method

if PROXY_USER and PROXY_PASSWORD:
conn.add_credentials(PROXY_USER, 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)
else:
return 'oops'
res = conn.getresponse()
content = res.read()
headers = dict(res.getheaders())
response.headers['Content-Type'] = headers['content-type']
response.status = int(res.status)
return content

and the following routes.py

routes_in = [('/examples/$anything',
'/proxy/proxy/proxy/examples/$anything')]

This will proxy http://web2py.com for urls startinsg with /
examples/

Fran

unread,
Jan 23, 2010, 3:08:30 PM1/23/10
to web2py-users
On Jan 23, 7:24 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Here is your proxy port of he Django one but without the httplib2
> dependency).

Awesome!

Checking it out now...

F

mdipierro

unread,
Jan 23, 2010, 3:55:33 PM1/23/10
to web2py-users
It is a bit clunky to configure because you have to use routes. You
can have multiple controllers to proxy different servers. Similarly to
the original Django code it does not carry forward headers from the
request. This means range requests, if modified since, streaming, does
not work. It is a bit slow.

Fran

unread,
Jan 23, 2010, 7:45:00 PM1/23/10
to web2py-users
On Jan 23, 8:55 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> It is a bit clunky to configure because you have to use routes. You
> can have multiple controllers to proxy different servers. Similarly to
> the original Django code it does not carry forward headers from the
> request. This means range requests, if modified since, streaming, does
> not work. It is a bit slow.

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 :)

Many thanks,
Fran.

mdipierro

unread,
Jan 24, 2010, 4:48:54 AM1/24/10
to web2py-users
This is a proxy server (just very limited) and can proxy only one
server.

mdipierro

unread,
Jan 24, 2010, 11:32:56 AM1/24/10
to web2py-users
I should add that the original Django Proxy also did caching of the
pages. The one I send you did not. Is this the functionality you need?
It could be added easily adding

if request.env.request_method=='GET':
proxy=cache(request.env.path_info,cache.disk,3600)(proxy)

Massimo

On Jan 23, 6:45 pm, Fran <francisb...@googlemail.com> wrote:

John Heenan

unread,
Jan 24, 2010, 7:44:58 PM1/24/10
to web2py-users
On Jan 25, 2:32 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I should add that the original Django Proxy also did caching of the
> pages. The one I send you did not. Is this the functionality you need?
> It could be added easily adding
>
> if request.env.request_method=='GET':
>     proxy=cache(request.env.path_info,cache.disk,3600)(proxy)
>

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.

John Heenan

John Heenan

unread,
Jan 24, 2010, 8:32:05 PM1/24/10
to web2py-users
On Jan 25, 10:44 am, John Heenan <johnmhee...@gmail.com> wrote:
> The __call__ function of the Cache global class instance, cache, is

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
compileapp.py.

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
errors appear?

John Heenan

Richard

unread,
Feb 21, 2010, 11:03:05 PM2/21/10
to web2py-users
did you get anywhere with your proxy? I am after a web2py proxy that
supports redirects, authentication, and passing headers.

The above snippet seems to proxy internal content rather than fetch
external content like the Django example.

On Jan 24, 11:45 am, Fran <francisb...@googlemail.com> wrote:
> On Jan 23, 8:55 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > It is a bit clunky to configure because you have to use routes. You

> > can have multiple controllers toproxydifferent servers. Similarly to

Richard

unread,
Feb 22, 2010, 7:31:12 AM2/22/10
to web2py-users
> The above snippet seems to proxy internal content rather than fetch
> external content like the Django example.

whoops, the Django snippet also does this.

mdipierro

unread,
Feb 23, 2010, 1:41:47 AM2/23/10
to web2py-users
I just rewrote the Django on th web2py. It should be easy to change
it.
Reply all
Reply to author
Forward
0 new messages