[Web-SIG] [server-side] request/response objects

Ian Bicking ianb at colorstudy.com
Thu Oct 30 12:37:27 EST 2003

On Thursday, October 30, 2003, at 11:02 AM, Randy Pearson wrote:
>> ... the big
>> difference between the two is that request should be read only while
>> response can have its state altered....
> If request is read-only, how would you create unit tests for other
> components? A testing harness would need the ability to instantiate and
> alter pseudo requests outside of the HTTP server context.

You'd be able to create artificial requests, and copy requests with 
changes.  Immutable objects usually have to have better support for 
these sorts of things for just this reason.  So maybe you'd have 
something like:

     # Ignoring some details here...
     vars = request.vars
     vars.update({'action': 'delete'})
     forward(request.clone(path='/target/delete', variables = vars))


     req = HTTPRequest(variables={}, method='GET', ...)

While perhaps with CGI you'd use:

    req = HTTPRequest.fromEnvironment()

(.fromCGI()? just .cgi()?)

Anyway, I think there's compatibility problems with this, but if I was 
doing it from scratch I might do this.  (Immutability would be a little 
soft, though -- you could, for instance, set the response for the 
request after the object was created, but you could change the response 
one it had been set)

Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org

More information about the Web-SIG mailing list