How to return a compressed response?

My base is the simple HttpListener tutorial. I'm try to respond to request with gzip compression with the handler below. It works fine when my request declare it doesn't accept gzip or deflate compression. When I use a gzip or deflate compatible browser,
it returns an empty string.