Make cowlib a proper dependency

Start moving a few functions from Cowboy into cowlib.