[Twisted-web] some questions about twisted.web

Jack Moffitt jack at chesspark.com
Tue Apr 7 11:46:48 EDT 2009


I just wrote a simple tool to make my AJAX app development cycle
better.  It's a tiny web server that serves up the current directory
along side some reverse proxies.  You can find the current code here:

http://github.com/metajack/tape/tree/master

In writing this I ran into a number of issues with twisted.web.  I'm
pretty sure some of these are bugs, but I wanted to get some feedback
here before I filed them.

* HTTPFactory seems only able to log to files.  It takes a path name,
not a file like object.  This makes it very difficult to log to
stdout, as I have to override log() in my own class.  This in turns
means cherry picking a global out of twisted.web - fun!

* log() never gets called when a ReverseProxyResource is used.  It
appears as though request.finish() is never called, though I wasn't
able to fully track this down.  I find this behavior very odd.

* static.File, when given a directory, creates instances of itself to
handle children.  This code completely fails for me with when I
subclassed static.File.  Note that my class only has a few
construction parameters, while static.File has 5.  This is not
documented.  It would be nice if the code could detect this case and
tell me that I have to overload createSimilarFile.

* The only way to stick something in the tree at an arbitrary location
seems to be to walk the tree to that spot, creating dummy locations as
you go.  I find it extremely weird coming from several other web
frameworks.  There is nothing else but the concept of "hey you!  get
me child X". This makes it pretty hard to implement anything better
than walking the tree since state would have to be collected over the
traversal.

* Related to the above, the handling of foo vs. foo/ is pretty
confusing.  foo/ is considered the '' child of foo.  This is pretty
yuck to me.  Unfortunately, I don't have any creative suggestions
about how to do it better right now.

* ReverseProxyResource returns nothing if you don't give it a '/' at
the end.  I had to work around this by doing a redirect in the
subclass and then returning a new ReverseProxyResource when the ''
child is accessed.  It seems that if ReverseProxyResource's path is
'', it just keels over with no error.


These combined to make what should have been a few lines of code and
an hour into 3-4 hours and almost 150+ lines.  Most of the time I
spent tracing through the Twisted source trying out figure out where
the weird stuff was coming from.  And after all that logging still
doesn't work right.

jack.



More information about the Twisted-web mailing list