Make the permalink server more closely mimic the behavior of the /permalink handler

Also incorporate some bugfixes from Ira, and the correction to use JSON for the get handler.