Separate http status functions

This commit is contained in:
René Linder 2023-03-29 10:37:20 +02:00
parent 1e0ca0b1b1
commit d892791ab6
3 changed files with 162 additions and 0 deletions

123
inc/lweb_http_status.pbi Normal file
View file

@ -0,0 +1,123 @@
;********************************
;*
;* lweb_http_status.pbi
;*
;* LiHaSo Webserver Default status.
;*
;* Configuration Module for Configs.
;*
; configuration\status("number")\status = "200"
; configuration\status("number")\file = ""
; configuration\status("number")\header = "200 Ok"
; configuration\status("number")\message = ""
; configuration\status("number")\template = #False
; configuration\status("number")\content = #False
;*
;* Default status components
;* Please add here only rfc7231 codes.
;*
Procedure status_defaults()
;Import XML cfg/default_http_status_codes.xml resp config
Protected ReadedXML.s, FileHandle.i, XMLHandle.i
FileHandle = ReadFile(#PB_Any, configuration\config_file("status_xml")\name)
If IsFile(FileHandle)
ReadedXML = ReadString(FileHandle, #PB_File_IgnoreEOL)
CloseFile(FileHandle)
XMLHandle = ParseXML(#PB_Any, ReadedXML)
If XMLHandle And XMLStatus(XMLHandle) = #PB_XML_Success
ExtractXMLMap(MainXMLNode(XMLHandle), configuration\status())
Else
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Info, "Import of the File:"+configuration\config_file("status_xml")\name+" failed.")
EndIf
Else
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Info, "Could not open File:"+configuration\config_file("status_xml")\name+" .")
EndIf
EndProcedure
Procedure.s status_get_file(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\file
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\file
Else
ProcedureReturn "Internal"
EndIf
EndProcedure
Procedure.s status_get_header(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\header
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\header
Else
ProcedureReturn "500 Internal Server Error"
EndIf
EndProcedure
Procedure.s status_get_message(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\message
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\message
Else
ProcedureReturn "500 Internal Server Error"
EndIf
EndProcedure
Procedure.s status_get_message_body(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\message_body
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\message_body
Else
ProcedureReturn ""
EndIf
EndProcedure
Procedure status_get_template(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\template
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\template
Else
ProcedureReturn #True
EndIf
EndProcedure
Procedure status_get_content(status.s, UUID.s="Default")
If UUID <> "Default"
If configuration\hosts(UUID)\status(status)\status = status
ProcedureReturn configuration\hosts(UUID)\status(status)\content
EndIf
EndIf
If configuration\status(status)\status = status
ProcedureReturn configuration\status(status)\content
Else
ProcedureReturn #True
EndIf
EndProcedure

View file

@ -0,0 +1,18 @@
;********************************
;*
;* lweb_http_status.pbi
;*
;* LiHaSo Webserver Default status Headerfile.
;*
;* Configuration Module for Configs.
;*
;* Please add here only rfc7231 codes.
Declare.s status_get_file(status.s, UUID.s="Default")
Declare.s status_get_header(status.s, UUID.s="Default")
Declare.s status_get_message(status.s, UUID.s="Default")
Declare.s status_get_message_body(status.s, UUID.s="Default")
Declare status_get_template(status.s, UUID.s="Default")
Declare status_get_content(status.s, UUID.s="Default")

View file

@ -0,0 +1,21 @@
;********************************
;*
;* lweb_http_status.pbi
;*
;* LiHaSo Webserver Default status Headerfile.
;*
;* Configuration Module for Configs.
;*
;* Please add here only rfc7231 codes.
Structure http_status_codes
status.s ;Error Number
file.s ;Error File or "Integrated" for default Message as Template
header.s ;Error Header message for #http_head_status
message.s ;Error Message for Templated
message_body.s ;Error Message Body for Templated
template.b ;Is it a Template {ErrorNo}=error and {Message}=message and {Message_body}=message_body need to be there
content.b ;has it a content to send. (200 for ex. has no content who need to be processed.)
Map head_fields.http_headerfield()
EndStructure