[Twisted-web] Peculiarity with putChild() using the root of the webserver

Glyph glyph at twistedmatrix.com
Thu Nov 15 02:55:58 EST 2012


Hi Rich,

On Nov 14, 2012, at 7:05 PM, Rich Brown <richb.hanover at gmail.com> wrote:

> I have been playing with Twisted 12.2.0, and encountered this minor infelicity:

10 points for use of the word "infelicity".

> 1) Files not at the root of the web server work as expected:
> 
> a) putChild("foo", File("some-directory")) works as expected - URL is http://example.com/foo/
> 
> b) Navigating to the directory "bar" within "foo" gives a URL of http://example.com/foo/bar/ as expected.

Glad to hear it.

> 2) Files at the root of the web server wind up with an extra "/" in the URL:
> 
> a)  putChild("", File("some-directory")) yields a URL of http://example.com//   <-- note double slash

This is not the root of the web server.

The thing you are calling putChild *on* is the root of the web server.  You are placing a directory as the index of another directory.  This is obviously a sort of silly thing to do, but it is nevertheless possible.

> b) navigating to the same directory "bar" gives: http://example.com//bar   <-- double-slash again...

Think of this as ".getChild('').getChild('bar')" rather than "double-slash".  Or rather, .getChild(x).getChild(y) where x and y happen to be '' and 'bar' respectively; there just isn't anything special about '' other than it looking funny to humans.

> Conclusion:
> 
> I think it would make sense to special the case of the root directory and not output a double "//" in the URL.

I think the thing to do would be to provide some better debugging / diagnostic / visualization tools to allow people to see what sort of hierarchy they've constructed, since this is in some sense an entirely sensible thing.  I was momentarily tempted to say that we should make it an error, but then I realized that while constructing hierarchies this way is perhaps gauche according to the idioms of the web, is is in no way incorrect, and there's no reason to break people's programs for doing it.

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20121114/3a0a0103/attachment.htm 


More information about the Twisted-web mailing list