Fixed example in doc string

We have to pass a HTTPHeaders object to write_headers()
Merge pull request #1222 from glaslos/patch-1

Fixed example in doc string
Change connection-refused test from localhost to 127.0.0.1.

This might be contributing to occasional timeouts on travis-ci
(on the theory that some other test may be listening on the
same port on ::1).

Also explicitly stop the test if connect_callback is called.
Merge pull request #1 from tornadoweb/master

rebase master