1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/monit/files/httpd_echo.py
Felix Fontein 424d706f92
Fix more copyright lines, add more default copyright lines (#5095)
* Fix copyright lines.

* Add default copyright line.
2022-08-08 14:24:58 +02:00

51 lines
1.3 KiB
Python

# Copyright (c) 2020, Simon Kelly <simongdkelly@gmail.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import daemon
try:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
def write_to_output(stream, content):
stream.write(content)
except ImportError:
from http.server import BaseHTTPRequestHandler, HTTPServer
def write_to_output(stream, content):
stream.write(bytes(content, "utf-8"))
hostname = "localhost"
server_port = 8082
class EchoServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
write_to_output(self.wfile, self.path)
def run_webserver():
webServer = HTTPServer((hostname, server_port), EchoServer)
print("Server started http://%s:%s" % (hostname, server_port))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")
if __name__ == "__main__":
context = daemon.DaemonContext()
with context:
run_webserver()