You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Mark Thias <Ma...@bnpi.com> on 2003/12/17 22:22:14 UTC

[users@httpd] RewriteMap script puts newline character in URL

I'm trying to use a RewriteMap and a RewriteRule for load balancing. I use a
python script in the RewriteMap to modify the URL but I get a newline
character in the URL which causes a browser error.

HTTP ERROR: 404 /ctms/%0D Not Found 

My environment is as follows: 
 1. Apache 2.0.48
 2. Win2K 5.00.2195 Service Pack 3
 3. Python23

My httpd.conf looks as follows:

RewriteEngine on
RewriteLogLevel 20
RewriteLog rewrite.log
RewriteMap servers "prg:C:/Tools/Python23/python.exe c:/proxy.py"
RewriteRule ^/ctms/(.*) ${servers:$1}  [P,L]

My python script:

#!c:\Tools\Python23\python.exe

count=0

import sys
import string
import os

if __name__ == "__main__":
    servers = ['http://server1:8080/ctms/','http://server2:8080/ctms/']
    while 1:
        data = sys.stdin.readline()
        if not data:
            break
        count = (count+1) % 2
        print servers[count]  ( remaps correctly but puts newline character
in URL )
#        sys.stdout.write("%s" % servers[count])  (tried this but causes
hang)
#        sys.stdout.write("%s\n" % servers[count])  (tried this, same as
print)
        sys.stdout.flush()  ( if I don't have this, does not remap )


Rewrite.log:

(2) init rewrite engine with requested uri /ctms/
(3) applying pattern '^/ctms/(.*)' to uri '/ctms/'
(2) init rewrite engine with requested uri /ctms/
(3) applying pattern '^/ctms/(.*)' to uri '/ctms/'
(5) map lookup OK: map=servers key= -> val=http://server1:8080/ctms/
198.213.32.14 - - [17/Dec/2003:15:12:20 --0600]
[server1/sid#23c590][rid#47e9c0/initial] (2) rewrite /ctms/ ->
http://server1:8080/ctms/ 198.213.32.14 - - [17/Dec/2003:15:12:20 --0600]
[server1/sid#23c590][rid#47e9c0/initial] (2) forcing proxy-throughput with
http://server1:8080/ctms/ 198.213.32.14 - - [17/Dec/2003:15:12:20 --0600]
[server1/sid#23c590][rid#47e9c0/initial] (1) go-ahead with proxy request
proxy:http://server1:8080/ctms/<newline character here> [OK]

Thank you for any leads you may have to this problem.

Mark Thias
  


This email may contain confidential and privileged material for the sole use
of the intended recipient. Any review or distribution by others is strictly
prohibited.  If you are not the intended recipient please contact the sender
and delete all copies.

Re: [users@httpd] RewriteMap script puts newline character in URL

Posted by André Malo <nd...@perlig.de>.
* Mark Thias <Ma...@bnpi.com> wrote:

> I'm trying to use a RewriteMap and a RewriteRule for load balancing. I use a
> python script in the RewriteMap to modify the URL but I get a newline
> character in the URL which causes a browser error.
> 
> HTTP ERROR: 404 /ctms/%0D Not Found 

Well, this is half a windows newline. (CR)
mod_rewrite should recognize it. Can you please file a bugreport regarding
the issue? (That way it doesn't get forgotten) A workaround for now is
described below.

> #!c:\Tools\Python23\python.exe

try adding the -u commandline option, like

#!c:\Tools\Python23\python.exe -u

If it doesn't work, use the -u option in your RewriteMap definition.

>         sys.stdout.flush()  ( if I don't have this, does not remap )

If you're using -u, this line is probably no longer necessary. In particular
it switches the channels (stdin/out/err) to unbuffered and binary handling.

(all untested, as usual ;-)

nd

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org