Extract handler code.

Gonna try to make it return an http.Handler next.  Having trouble
with that bit.