problem with web.changequery

10 views
Skip to first unread message

Anand

unread,
Dec 11, 2006, 11:20:42 PM12/11/06
to we...@googlegroups.com

I am using a lighttp+fastcgi to run my web.py application with the
following rewrite rule.

url.rewrite-once =(
"^/(.*)$" => "/run.py/$1",
)

When i use web.changequery, it includes /run.py in the changed query.

For example when i am at url /hello and call web.changequery
(m="edit"), it gives
/run.py/hello?m=edit
instead of
/hello?m=edit

I think it is because web.changequery addes web.ctx.homepath to the
web.ctx.path before changing the query.
any workarounds?


Aaron Swartz

unread,
Dec 12, 2006, 12:09:00 AM12/12/06
to we...@googlegroups.com
> I think it is because web.changequery addes web.ctx.homepath to the
> web.ctx.path before changing the query.
> any workarounds?

Yes, I think you can use lighttpd to set the environment variable
REAL_SCRIPT_NAME to include run.py and then web.py should strip it out

Anand

unread,
Dec 12, 2006, 12:47:16 AM12/12/06
to we...@googlegroups.com

How to set environment variables from lighttpd?

I tried setting REAL_SCRIPT_NAME by executing
os.environ['REAL_SCRIPT_NAME'] = "/run.py"

But it doesnt work.

web.py doesnt strip anything in setting homepath. This is the code,
which sets ctx.homepath and ctx.path

ctx.homepath = os.environ.get('REAL_SCRIPT_NAME', env.get
('SCRIPT_NAME', ''))
ctx.path = env.get('PATH_INFO')
# http://trac.lighttpd.net/trac/ticket/406 requires:
if env.get('SERVER_SOFTWARE', '').startswith('lighttpd/'):
ctx.path = lstrips(env.get('REQUEST_URI').split('?')[0],
os.environ.get('REAL_SCRIPT_NAME', env.get
('SCRIPT_NAME', '')))

However setting REAL_SCRIPT_NAME to "" solved the problem.

btw, http://trac.lighttpd.net/trac/ticket/406 is
PHP SCRIPT_NAME, PATH_INFO, PHP_SELF and others improperly
converted to lowercase
What is the relation between the code and the ticket#406? some typo?


Sam

unread,
Dec 12, 2006, 11:03:50 PM12/12/06
to web.py

Anand wrote:
> How to set environment variables from lighttpd?

I've already answered this whole thing. Try searching the group. :-)

http://groups.google.com/group/webpy/browse_thread/thread/e784d1f14e4d67d7/80a0d561dc69d589?lnk=gst&q=REAL_SCRIPT_NAME&rnum=2#80a0d561dc69d589

Sam wrote:
> Alex K wrote:
> > Sure I can but how do I manage to setup lighttpd so that I don't have
> > to rewrite the url mapping.
>
> Well web.py uses web.ctx.home to figure out where things are, and this
> is calculated from the environmental variable SCRIPT_NAME, which can be
> overridden with REAL_SCRIPT_NAME, so for true hackery:
>
> fastcgi.server += ( "/webtest.py" => ( (
> "socket" => "/tmp/fastcgi.socket",
> "bin-path" => "/patch/to/webpy/app.py",
> "max-procs" => 1,
> # Stop 404s if not in docroot
> "check-local" => "disable",
> "bin-environment" => (
> # Mount location - note missing trailing '/'
> "REAL_SCRIPT_NAME" => "/myapp1"
> ),
> ) ) )
>
> I tested this on the latest svn tree, although from brief inspection it
> looks like it'll hold on 0.1xy (production) too.
>
> > I tried to play with the docroot option of fastcgi.server but I get a
> > webpy not found. Looking into the logs show that web.py does not take
> > into account the docroot option.
>
> To stop that you need to use "check-local" => "disable" in your fastcgi
> settings. That way lighttpd won't check to see if the file exists
> first. I included in the above example.
> See: http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI#toc3
>
> Sam.

Anand

unread,
Dec 13, 2006, 3:24:33 AM12/13/06
to we...@googlegroups.com

On 13-Dec-06, at 9:33 AM, Sam wrote:

>>
>> Well web.py uses web.ctx.home to figure out where things are, and
>> this
>> is calculated from the environmental variable SCRIPT_NAME, which
>> can be
>> overridden with REAL_SCRIPT_NAME, so for true hackery:
>>
>> fastcgi.server += ( "/webtest.py" => ( (
>> "socket" => "/tmp/fastcgi.socket",
>> "bin-path" => "/patch/to/webpy/app.py",
>> "max-procs" => 1,
>> # Stop 404s if not in docroot
>> "check-local" => "disable",
>> "bin-environment" => (
>> # Mount location - note missing trailing '/'
>> "REAL_SCRIPT_NAME" => "/myapp1"
>> ),
>> ) ) )
>>

Thanks.

Reply all
Reply to author
Forward
0 new messages