aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/kong.py
blob: c39542f1bc6bc0a07a0e3798d36214518616dfb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

from http.server import HTTPServer, CGIHTTPRequestHandler
import random

class SimpleHTTPRequestHandler(CGIHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/services/test':
            self.send_response(404)
        else:
            self.send_response(200)
        self.send_header('Content-Type', 'application/json')
        self.end_headers()
        self.wfile.write(b'{ "data": [] }')

    def do_POST(self):
        self.send_response(201)
        self.end_headers()
        self.wfile.write(b'Hello, world!')

    def do_PUT(self):
        if bool(random.getrandbits(1)):
            self.send_response(200)
        else:
            self.send_response(201)
        self.end_headers()
        self.wfile.write(b'Hello, world!')


httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()