Equivalent of websocket directive for normal web request

I just playing around with the websocket directive:-

localhost:4000
websocket /ws "python ws.py"

And the python script ws.py:-

import sys
import time

while True:
  line=sys.stdin.readline().rstrip()
  if line:
    sys.stdout.write(line[::-1]+'\n')
    sys.stdout.flush()
  else:
    sys.stdout.flush()
    time.sleep(1)

Impressing ! But now if I need to listen to some webhook as part of this websocket app, I need to run python app server and proxy it from caddy. Why can’t we have similar directive to process normal web request like above too ?

Like the proxy directive does? Or you mean something that goes to stdin? If so, probably because there hasn’t been any demand for it…

Using proxy require me to manage another process. In websocket example above, it run python ws.py when there’s incoming connection, and then terminate it when the connection closed. But thinking further about this started to feel like this is exactly what CGI is.

Yep, basically. :slight_smile: The websocket directive even implements a subset of the CGI spec.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.