Protocols.HTTP.Server.Request()->response_and_finish() should not modify m
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=6499
Reported by Per Cederqvist ceder@lysator.liu.se
I think it makes sense to use response_and_finish() like this:
constant forbidden = ([ "error":403, "data":"Forbidden" ]);
void handle_request( Protocols.HTTP.Server.Request id )
{
if (some_condition( id ) )
id->response_and_finish( forbidden );
// normal processing... }
This does not work reliably, however. The response_and_finish() method alters the "forbidden" mapping, so what one client does can affect the processing of future requests.
For example, if one client supplies a "Range: bytes=999-1020" header it will get a 416 response. The next forbidden request will also get the same 416 response (at least if it contains no "Range:" header).
I think response_and_finish() should be careful not to modify its argument. Failing that, the documentation should warn that m is modified and that code like the one above is broken.
I'm attaching a proposed fix.