zotonic/webzmachine — pull request #12 by amiramix (2013-07-26 14:14:47+00:00)
Title: Fix crash in performance logs when the dispatch rule doesn't match

To reproduce the crash just enable perf logs and try to open a page which doesn't match the dispatch rules (e.g. http://site:8000/manual). The crash happens because `end_time` and `finish_time` in wm_log_data are not being initialized.

I've added the initialization of `end_time` to `webmachine_perf_logger` which all functions have to call in order to log the performance log (thus I'm removing the initialization of `end_time` in `webmachine_mochiweb:loop` because it will be initialized in the logger function anyway).

As for initialization of `finish_time` the standard way is setting that field in the `send_response/1` function. However, most functions in the dispatch loop were skipping that initialization because of some reason and were calling the `send_response/2` function directly, which was leaving that field empty. I consider that as a mistake and so I made the `send_response/2` private to not confuse people in the future.

Of course I checked that no other part of webzmachine sources use `send_response/2`, however there is one usage in Zotonic itself which I will send in another pull request.