Ensure we write json header before writing bytes

In net/http once we've issued a Write() the response is sent
over the wire including the header! The tests didn't catch
this because I used a net/http/httptest.RequestRecorder
which doesn't follow those semantics.