Implement onBeforeRequest event

Fixes #27