Add lhs_web library helper include for easy lweb library creation

This commit is contained in:
René Linder 2023-03-30 08:19:38 +02:00
parent 7be5b7e21c
commit 80af41e7e6

130
NET/lhs_web_helper.pbi Normal file
View file

@ -0,0 +1,130 @@
;************************
;* Library : lhs_web_helper.pbi
;*
;* The lhs_web_helper library is to build simple dynamic linked libraries for the lweb server.
;*
;* Created and develobed by Linder Hard- und Software
;*
;*
DeclareModule lhs_web_helper
Declare.s MapToJSONString(Map ConvertMap.s())
Declare.s mimetype(file.s)
#cha_R_ResponseType = "ResponseType" ;Element ResponseType :Mimetype
#cha_R_ResponseContentType = "ResponseContentType" ;Element ResponseContentType :#response_string , #response_Memory
#cha_R_MemoryAdress = "MemoryAdress" ;Element MemoryAdress :Converted to String
#cha_R_MemorySize = "MemorySize" ;Element MemorySize :Converted to String
#cha_R_StringBase64 = "StringBase64" ;Element StringBase64 :Base64 Encoded String
#cha_R_http_head_status = "HeaderStatus" ;200 OK 300 Error 500 Server Error usw.
#response_string = "response_string"
#response_Memory = "response_memory"
#error_string = "error"
#http_head_method = "method:"
#http_head_request = "request:"
#http_head_protocol = "protocol:"
#http_head_query = "query:"
#http_head_status = "status:"
#http_head_date = "date:"
#http_head_server = "server:"
#http_head_content_length = "content-length:"
#http_head_content_type = "content-type:"
#http_head_connection = "connection:"
#http_head_keep_alive = "keep-alive:"
#http_head_cookie = "cookie:"
#http_head_set_cookie = "set-cookie:"
#http_head_redirect = "location:"
;200er codes
#http_state_200 = "200 Ok"
#http_state_201 = "201 Created"
#http_state_202 = "202 Accepted"
#http_state_203 = "203 Non-Authoritative Information"
#http_state_204 = "204 No Content"
#http_state_205 = "205 Reset Content"
#http_state_206 = "206 Partial Content"
#http_state_207 = "207 Multi-Status"
#http_state_208 = "208 Already Reported"
#http_state_226 = "226 IM Used"
;300er codes
#http_state_300 = "300 Multiple Choices"
#http_state_301 = "301 Moved Permanently"
#http_state_302 = "302 Found"
#http_state_303 = "303 See Other"
#http_state_304 = "304 Not Modified"
#http_state_307 = "307 Temporary Redirect"
#http_state_308 = "308 Permanent Redirect"
;400er codes
#http_state_400 = "400 Bad Request"
#http_state_401 = "401 Unauthorized"
#http_state_402 = "402 Payment Required"
#http_state_403 = "403 Forbidden"
#http_state_404 = "404 Not Found"
;500er codes
#http_state_500 = "500 Internal Server Error"
#http_state_501 = "501 Not Implemented"
EndDeclareModule
Module lhs_web_helper
Procedure.s MapToJSONString(Map ConvertMap.s())
Protected MyJSON
Protected.s Response
MyJSON = CreateJSON(#PB_Any)
If MyJSON
InsertJSONMap(JSONValue(MyJSON), ConvertMap())
Response = ComposeJSON(MyJSON)
FreeJSON(MyJSON)
ProcedureReturn Response
EndIf
ProcedureReturn #error_string
EndProcedure
Procedure.s mimetype(file.s)
Select LCase(file)
Case "pdf"
ProcedureReturn "application/pdf"
Case "zip"
ProcedureReturn "application/zip"
Case "gz"
ProcedureReturn "application/gzip"
Case "doc"
ProcedureReturn "application/msword"
Case "xls"
ProcedureReturn "application/vnd.ms-excel"
Case "ppt"
ProcedureReturn "application/vnd.ms-powerpoint"
Case "png"
ProcedureReturn "image/png"
Case "gif"
ProcedureReturn "image/gif"
Case "jpg"
ProcedureReturn "image/jpeg"
Case "jpeg"
ProcedureReturn "image/jpeg"
Case "txt"
ProcedureReturn "text/plain"
Case "html"
ProcedureReturn "text/html"
Case "htm"
ProcedureReturn "text/html"
Case "mss"
ProcedureReturn "text/html"
Case "php"
ProcedureReturn "text/html"
Case "css"
ProcedureReturn "text/css"
Case "js"
ProcedureReturn "text/javascript"
Default
ProcedureReturn "application/octet-stream"
EndSelect
EndProcedure
EndModule