crowdsec/scripts/func_tests/mock_http_server.py
Shivam Sandbhor e89543f725
Add functional tests for plugins (#941)
* Add functional tests for plugins

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
(cherry picked from commit 1a11c87296454aac1ebbc95c06b813ae67c91819)

* Update plugin dir in functional tests

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>

* Update plugin process config in func tests

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>

* Robust config replacement

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
2021-09-08 15:22:34 +02:00

26 lines
No EOL
812 B
Python

import json
from http.server import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
request_path = self.path
request_body = self.rfile.read(int(self.headers['Content-Length']))
request_body = json.loads(request_body)
log = {
"path": request_path,
"status": 200,
"request_body": request_body,
}
print(json.dumps(log))
self.send_response(200)
self.send_header('Content-type','application/json')
self.end_headers()
self.wfile.write(json.dumps({}).encode())
return
def log_message(self, format, *args):
return
if __name__ == "__main__" :
server = HTTPServer(('', 9999), RequestHandler)
server.serve_forever()