Pass a valid context

This commit is contained in:
Soam Vasani
2016-11-19 11:01:28 -08:00
parent 04efe0bad4
commit 8a9559be1f
+9 -4
View File
@@ -3,12 +3,16 @@
import imp
from http.server import BaseHTTPRequestHandler, HTTPServer
#
# Load the file.
#
codepath = '/userfunc/user'
userfunc = None
#
# Request context that's passed to user functions
#
class Context:
def __init__(self, handler):
self.handler = handler
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
global userfunc
@@ -23,7 +27,8 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
global userfunc
try:
print("GET request")
message = userfunc(None)
ctx = Context(self)
message = userfunc(ctx)
self.send_response(200)
self.end_headers()
self.wfile.write(bytes(message, "utf8"))