Skip to content

Instantly share code, notes, and snippets.

@andreif
Last active January 11, 2024 21:04
Show Gist options
  • Select an option

  • Save andreif/439157471eabc54728cbd00eb32b4bff to your computer and use it in GitHub Desktop.

Select an option

Save andreif/439157471eabc54728cbd00eb32b4bff to your computer and use it in GitHub Desktop.

Revisions

  1. andreif revised this gist Jan 11, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions simple.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    python -m http.server -d /tmp 8080
  2. andreif revised this gist Jan 11, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions wsgi-server.py
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@


    def app(environ, start_response):
    start_response("200 OK", [("Content-Type", "application/json; charset=utf-8")])
    return [b"true"]
    start_response('200 OK', [('Content-Type', 'application/json; charset=utf-8')])
    return [b'true']


    simple_server.ServerHandler.server_software = ""
    with simple_server.make_server(host="0.0.0.0", port=8080, app=app) as _:
    simple_server.ServerHandler.server_software = ''
    with simple_server.make_server(host='0.0.0.0', port=8080, app=app) as _:
    print(f"Serving on port {_.server_port}...")
    _.serve_forever()
  3. andreif revised this gist Jan 11, 2024. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions wsgi-server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    from wsgiref import simple_server


    def app(environ, start_response):
    start_response("200 OK", [("Content-Type", "application/json; charset=utf-8")])
    return [b"true"]


    simple_server.ServerHandler.server_software = ""
    with simple_server.make_server(host="0.0.0.0", port=8080, app=app) as _:
    print(f"Serving on port {_.server_port}...")
    _.serve_forever()
  4. andreif revised this gist Jan 11, 2024. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions http-server.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    import http.server as s
    import http.server


    class RequestHandler(s.BaseHTTPRequestHandler):
    class Handler(http.server.BaseHTTPRequestHandler):
    def __getattr__(self, item):
    if item.startswith('do_'):
    return self.default
    @@ -18,9 +18,9 @@ def default(self):
    self.wfile.write(b'ok')


    with s.ThreadingHTTPServer(('0.0.0.0', 8080), RequestHandlerClass=RequestHandler) as h:
    print(f"Serving on port {h.server_port}...")
    with http.server.ThreadingHTTPServer(('0.0.0.0', 8080), RequestHandlerClass=Handler) as _:
    print(f"Serving on port {_.server_port}...")
    try:
    h.serve_forever()
    _.serve_forever()
    except KeyboardInterrupt:
    exit(0)
  5. andreif created this gist Jan 11, 2024.
    26 changes: 26 additions & 0 deletions http-server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import http.server as s


    class RequestHandler(s.BaseHTTPRequestHandler):
    def __getattr__(self, item):
    if item.startswith('do_'):
    return self.default
    return getattr(super(), item)

    def default(self):
    print(self.command, self.path)
    print(self.headers)
    self.protocol_version = 'HTTP/1.0'
    self.send_response(200)
    self.send_header('a', '1')
    self.send_header('a', '2')
    self.end_headers()
    self.wfile.write(b'ok')


    with s.ThreadingHTTPServer(('0.0.0.0', 8080), RequestHandlerClass=RequestHandler) as h:
    print(f"Serving on port {h.server_port}...")
    try:
    h.serve_forever()
    except KeyboardInterrupt:
    exit(0)