[Twisted-web] disabling redirection

Markus Schiltknecht markus at bluegap.ch
Mon Jun 11 04:11:33 EDT 2007


Hi,

Jean-Paul Calderone wrote:
> You're going about this wrong, unfortunately.  "Twisted" won't issue a
> redirect based on the Host header.  Even "twisted.web" won't do that.

Okay, good to know. (And good it is that way)

> Some resource provided by twisted.web (or nevow, I forget what you're
> using) might, but only if you put it into your resource hierarchy.  Perhaps
> you could elaborate on how and of what your Site is constructed?  A minimal
> code example would be ideal, since it communicates exactly the problem
> you're having, instead of relying on the imperfect ability of other people
> to translate a prose description of a program back into the same program.

After the frustrating experience with various caches (server and browser 
side) interrupting and adding to the confusion, I didn't feel like 
compiling a test case, sorry.

Today, thanks to you motivating mail, I've tried again and tcpdump'ed 
the h*** out of it! I think I've finally tracked down what's bugging me: 
it's the addSlash = True forwarder (presumably in the nevow code).

(Sorry if that's the wrong list for nevow related stuff - is there a 
dedicated nevow mailing list?)

Here's how to reproduce my problem:

##### sample.tac #####

from nevow import rend, loaders
from nevow import tags as T
from nevow.appserver import NevowSite
from twisted.application import service, internet

class Child(rend.Page):
     addSlash = True
     docFactory = loaders.stan(T.html[ T.p[ "Hello, child!" ] ])

class Site(rend.Page):
     docFactory = loaders.stan(T.html[ T.p[ "Hello, world!" ] ])
     child_test = Child()

application = service.Application('sample')
internet.TCPServer(
     8081,
     NevowSite(Site(), logPath="web.log")
).setServiceParent(application)

##### telnet session to that server #####

markus at argodan:/home/markus# telnet localhost 8081
Trying 127.0.0.1...
Connected to argodan.
Escape character is '^]'.
GET / HTTP/1.1
Host: somewhere.com

HTTP/1.1 200 OK
Transfer-encoding: chunked
Date: Mon, 11 Jun 2007 07:59:37 GMT
Content-type: text/html; charset=UTF-8
Server: TwistedWeb/2.4.0

21
<html><p>Hello, world!</p></html>
0

GET /test HTTP/1.1
Host: somewhere.com

HTTP/1.1 302 Found
Transfer-encoding: chunked
Date: Mon, 11 Jun 2007 07:59:46 GMT
Content-type: text/html; charset=UTF-8
Location: http://somewhere.com:8081/test/     <--- I'VE STUMBLED OVER
Server: TwistedWeb/2.4.0                           THIS REDIRECT HERE

0

GET /test/ HTTP/1.1
Host: somewhere.com

HTTP/1.1 200 OK
Transfer-encoding: chunked
Date: Mon, 11 Jun 2007 07:59:55 GMT
Content-type: text/html; charset=UTF-8
Server: TwistedWeb/2.4.0

21
<html><p>Hello, child!</p></html>
0


So, the question now is: how do I tell nevow where it should redirect to 
in case of 'addSlash = True'? I don't want it to redirect to the 
internal port 8081.

[ Why does it use the Host: header field, but not the corresponding 
port? Maybe this has already been fixed and I only need an update? Or 
does this have a good reason for being as it is? ]

Thanks for you help.

Regards

Markus




More information about the Twisted-web mailing list