Pass a valid context
This commit is contained in:
@@ -3,12 +3,16 @@
|
|||||||
import imp
|
import imp
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
#
|
|
||||||
# Load the file.
|
|
||||||
#
|
|
||||||
codepath = '/userfunc/user'
|
codepath = '/userfunc/user'
|
||||||
userfunc = None
|
userfunc = None
|
||||||
|
|
||||||
|
#
|
||||||
|
# Request context that's passed to user functions
|
||||||
|
#
|
||||||
|
class Context:
|
||||||
|
def __init__(self, handler):
|
||||||
|
self.handler = handler
|
||||||
|
|
||||||
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
global userfunc
|
global userfunc
|
||||||
@@ -23,7 +27,8 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|||||||
global userfunc
|
global userfunc
|
||||||
try:
|
try:
|
||||||
print("GET request")
|
print("GET request")
|
||||||
message = userfunc(None)
|
ctx = Context(self)
|
||||||
|
message = userfunc(ctx)
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(bytes(message, "utf8"))
|
self.wfile.write(bytes(message, "utf8"))
|
||||||
|
|||||||
Reference in New Issue
Block a user