'Serve data from an IO stream over HTTP.'

@contextlib.contextmanager
def temporary_http_file_server(self, stream):

    class Handler(BaseHTTPServer.BaseHTTPRequestHandler, ):
        def do_GET(self):
            self.send_response(200)
            self.send_header('Content-Type', 'application/x-tar')
            self.end_headers()
            shutil.copyfileobj(stream, self.wfile)
    server = socketserver.TCPServer(('', 0), Handler)
    thread = threading.Thread(target=server.serve_forever)
    thread.setDaemon(True)
    thread.start()
    (yield ('http://%s:%s' % (socket.gethostname(), server.server_address[1])))
    server.shutdown()
