Repository navigation
Add current-header-handler and dispatch-logresp - #119
Conversation
|
@jeapostrophe I don't know if this is "clean" enough for you. I handled the response code at a lower level than you suggested, because I also want it to be able to log response code from Some concerns:
|
|
I've sometimes wanted (and have sometimes implemented) ways to interpose on response handlers. I haven't reviewed the code in detail—maybe you've already thought about this!—but one thing I wanted to flag is the use of a parameter for I'll try to make time to look at this more closely. |
|
I wonder if it wouldn't be better to extend Re. performance, I would suggest setting up a minimal server that displays some text and throwing some load at it with vegeta[1]. Raise your file descriptor limits before running the server and vegeta ( [1]: I like to use |
| (define (output-response-head conn raw-bresp [chunked? #f]) | ||
| (define bresp ((current-header-handler) | ||
| (struct-copy response raw-bresp | ||
| [output void]))) |
There was a problem hiding this comment.
I think voiding the output here makes it so no response can output any data (see output-response-body below). It should be safe to pass the unmodified response to the handler proc, and it should be the handler proc's responsibility not to do anything silly with it.
There was a problem hiding this comment.
Oh, ignore this. I misread the surrounding code, not realizing this was only outputting the headers. Still, it might make sense to allow processors to alter the output, too.
There was a problem hiding this comment.
This bresp is used only inside this function. response-output in output-response-body will be the original one. It is unaffected.
There was a problem hiding this comment.
I replied too late :)
The reason why I only target header as opposed to the whole response is that output-file (which in turn calls output-file/boundary) creates a fake response with correct header but empty body, and then uses output-response-head to print the header directly. Giving an appearance that the output field could be modified would be misleading for such cases.
|
I thought about modifying The top-level of the web-server is this: A connection is established once, and then it is used in a loop which could potentially invokes |
|
@LiberalArtist I tried your minimal example program, and it appears that And here are the results Note that both "struct:path/param"s in the response headers are correct. The bodies are of course incorrect, as you indicated in the mailing list. |
Add a new parameter `current-header-handler` which can be used to transform the "header" (including code, message -- everything but the body) right before it will be written to the output port. Use this new parameter to implement `dispatch-logresp`, a new dispatcher that consumes another dispatcher, and returns a dispatcher that acts like the input dispatcher, except that if the input dispatcher got dispatched, it will log request and response, just like how the Apache server does.
|
This is now ready for review. |
|
Thank you! |
Add a new parameter
current-header-handlerwhich can be usedto transform the "header" (including code, message -- everything but the
body) right before it will be written to the output port.
Use this new parameter to implement
dispatch-logresp, a new dispatcherthat consumes another dispatcher, and returns a dispatcher that acts
like the input dispatcher, except that if the input dispatcher is
dispatched, it will log request and response, just like how the
Apache server does.
Still need tests and documentation.
Partially fixes #54