mirror of
https://github.com/eliasrenman/gardentron.git
synced 2026-03-16 20:46:07 +01:00
feat: added body support
This commit is contained in:
@@ -39,16 +39,41 @@ class Endpoint:
|
||||
if endpoint != self.path and self.path != '*' or method != self.method:
|
||||
return
|
||||
try:
|
||||
body = get_body(request)
|
||||
if body:
|
||||
kwargs = dict(**kwargs, body=body)
|
||||
|
||||
val = function(instance, *args, **kwargs)
|
||||
respond(cl, 200, val)
|
||||
return val
|
||||
except HttpError as e:
|
||||
respond(cl, e.status,
|
||||
e.message)
|
||||
except Exception as e:
|
||||
print("Some other unkown error occured:", e)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
"""
|
||||
Please note that this only supports content-type 'application/json'
|
||||
"""
|
||||
|
||||
|
||||
def get_body(request: str):
|
||||
req = request.split("\r\n")
|
||||
content_type_index = -10
|
||||
for index in range(len(req)):
|
||||
item = req[index]
|
||||
|
||||
if item.find("Content-Type") != -1:
|
||||
if not item.find("application/json"):
|
||||
return
|
||||
content_type_index = index
|
||||
if (content_type_index + 4) == index:
|
||||
return item
|
||||
|
||||
|
||||
class ServerHandler(object):
|
||||
def __init__(self, s: socket.socket):
|
||||
not_found_endpoints = (self.__post_not_found,
|
||||
|
||||
Reference in New Issue
Block a user