File: zhttpreqhandler.py

package info (click to toggle)
pushpin 1.36.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,752 kB
  • sloc: cpp: 39,464; python: 970; sh: 132; ansic: 56; makefile: 35; php: 27
file content (23 lines) | stat: -rw-r--r-- 434 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# use route target zhttpreq/ipc:///tmp/zhttpreqhandler

import zmq
import tnetstring

zmq_context = zmq.Context()
sock = zmq_context.socket(zmq.REP)
sock.connect('ipc:///tmp/zhttpreqhandler')

while True:
	req = tnetstring.loads(sock.recv()[1:])

	resp = {
		'id': req['id'],
		'code': 200,
		'reason': 'OK',
		'headers': [
			['Content-Type', 'text/plain']
		],
		'body': 'hello there\n'
	}

	sock.send('T' + tnetstring.dumps(resp))