Provide
http_request
event with an object representing the request instead of the LSL parameters
request_id
,
method
,
body
I'd propose if possible an object with the following structure
type HTTPRequest = {
id: uuid,
method : "GET"|"POST"|"PUT"|"DELETE",
length: number, -- length of body
url: string, -- the url this request came in on
getBody: (self: HTTPRequest) -> string, -- retrieves body
getHeader: (self : HTTPRequest, header: string) -> string, -- maps to ll.GetHeader
setContentType: (self: HTTPRequest, contentType:number) -> (), -- maps to ll.SetContentType
respond: (self: HTTPRequest, status: number, body: string) -> (), -- maps to ll.HTTPResponse
getPath: (self: HTTPRequest) -> string, -- maps to ll.GetHeader with x-path-info
... -- other common headers
}
Example use
LLEvents:on("http_request",function(request)
print("HTTP", request.method)
print("Body Length", request.length)
if request.length < 500 then
print("Body", request:getBody())
end
print("Path", request:getPath())
request:respond(200, "OK")
end)
This would make http requests safer and easier to manage especially with large bodies no longer risking oom's
If
url
is not easily available now, it should be addable later with no effect to existing scripts