MCPcopy Create free account
hub / github.com/defold/defold / do_GET

Method do_GET

engine/script/test_script_server.py:28–79  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

26 return "Dynamo 1.0"
27
28 def do_GET(self):
29 to_send = ""
30 extra_headers = None
31
32 if self.path == "/":
33 a,b = self.headers.get('X-A', None), self.headers.get('X-B', None)
34 if a and b:
35 to_send = 'Hello %s%s' % (a, b)
36 else:
37 to_send = 'Hello'
38
39 elif self.path.startswith('/sleep'):
40
41 tokens = self.path.split('/')
42 sleeptime = 2.0
43 if len(tokens) > 2:
44 try:
45 sleeptime = float(tokens[2])
46 except:
47 self.send_response(500, "Could not parse time argument as float: %s" % self.path)
48 self.send_header("Content-type", "text/plain")
49 self.end_headers()
50 self.wfile.write(to_send.encode('ascii'))
51 return
52
53 sys.stdout.flush()
54 time.sleep( sleeptime )
55 to_send = "slept for %f" % sleeptime
56 else:
57 try:
58 import test_script_server_plugin
59 result = test_script_server_plugin.do_GET(self.path)
60
61 to_send = result['to_send']
62 extra_headers = result['headers']
63
64 except Exception as e:
65 pass
66
67 if to_send:
68 self.send_response(200)
69 else:
70 self.send_response(404)
71
72 self.send_header("Content-type", "text/plain")
73
74 if extra_headers:
75 for k,v in extra_headers.items():
76 self.send_header(k, v)
77
78 self.end_headers()
79 self.wfile.write(to_send.encode('ascii'))
80
81 def do_POST(self):
82 len = self.headers.get('Content-Length')

Callers

nothing calls this directly

Calls 7

send_responseMethod · 0.80
getMethod · 0.65
splitMethod · 0.65
floatFunction · 0.50
writeMethod · 0.45
encodeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected