def server(): server = http.Server(("127.0.0.1", 0), http.Connection) log.info("Server listening on port %d", server.server_port) server.app = http.Router([ (r"/demo/(.*)", Demo()), (r"/echo/(.*)", Echo()), (r"/json/", JSON()), (r"/range-demo/", RangeDemo()), (r"/request-info/(.*)", RequestInfo()), (r"/context/(.*)", Context()), (r"/close-context/(.*)", CloseContext()), (r"/server-error/(.*)", ServerError()), (r"/server-socket-error/(.*)", ServerSocketError()), (r"/client-error/(.*)", ClientError()), (r"/keep-connection/", KeepConnection()), (r"/partial-response/", PartialResponse()), ]) t = util.start_thread(server.serve_forever, kwargs={"poll_interval": 0.1}) try: yield server finally: server.shutdown() t.join()
def __init__(self, config): self._config = config self._server = uhttp.Server(config.images.socket, uhttp.Connection) # TODO: Make clock configurable, disabled by default. self._server.clock_class = util.Clock if config.images.socket == "": config.images.socket = self.address self._server.app = http.Router([ (r"/images/(.*)", images.Handler(config)), ]) log.debug("%s listening on %r", self.name, self.address)
def __init__(self, config): self._config = config self._server = http.Server( (config.images.host, config.images.port), http.Connection) # TODO: Make clock configurable, disabled by default. self._server.clock_class = util.Clock if config.images.port == 0: config.images.port = self.port self._secure_server() self._server.app = http.Router([ (r"/images/(.*)", images.Handler(config)), ]) log.debug("%s listening on port %d", self.name, self.port)
with req.clock.run("write"): f.write(chunk) count -= len(chunk) parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", action="store_true", help="Debug mode") parser.add_argument("-p", "--port", default=8000, help="listen port (default 8000)") args = parser.parse_args() logging.basicConfig( level=logging.DEBUG if args.debug else logging.INFO, format="%(asctime)s %(levelname)-7s (%(threadName)s) %(message)s") log.info("Starting server on port %s", args.port) server = http.Server(("", args.port), http.Connection) if args.debug: server.clock_class = util.Clock server.app = http.Router([ (r"/bench/(.*)", Bench()), (r"/stream/(.*)", Stream()), (r"/echo/(.*)", Echo()), ]) server.serve_forever()