Instant fastcgi scripts by just adding a decorator
from fastcore.utils import *
from fastcore.script import *
import subprocess,time,urllib
def c():
return "Content-type: text/html\r\n\r\n<html>" \
+ f'{sys.stdin.read()} ; {os.environ["QUERY_STRING"]}</html>\r\n'
p = Path('fcgi.sock')
@fastcgi(p)
def hello(): sys.stdout.write(c())
@threaded
def _f():
with hello() as srv: srv.handle_request()
proc = subprocess.Popen(['./http2fcgi'])
if p.exists(): p.unlink()
t = _f()
time.sleep(0.2)
res = urlread('http://localhost:6065/setup.py?a=1', foo='bar', greeting='你好')
print(urllib.parse.unquote(res.decode()))
proc.terminate()
addr = 'localhost',8003
@fastcgi(addr)
def hello(): sys.stdout.write(c())
time.sleep(0.5)
proc = subprocess.Popen('./http2fcgi -fcgi tcp://localhost:8003'.split())
t = _f()
time.sleep(0.2)
res = urlread('http://localhost:6065/setup.py?a=1', foo='bar', greeting='你好')
print(urllib.parse.unquote(res.decode()))
proc.terminate()