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
patchback[bot] 0d598c3542
Fix more copyright lines, add more default copyright lines (#5095) (#5096)
* Fix copyright lines.

* Add default copyright line.

(cherry picked from commit 424d706f92)

Co-authored-by: Felix Fontein <felix@fontein.de>
2022-08-08 15:19:46 +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()