Initial Websocket and Bugfix for prototype support
This commit is contained in:
parent
194245d3b6
commit
8574b29021
1 changed files with 154 additions and 122 deletions
270
lweb.pbi
270
lweb.pbi
|
@ -677,141 +677,173 @@ Module lhs_web
|
||||||
;{
|
;{
|
||||||
ldl::Logging(#http_method_get)
|
ldl::Logging(#http_method_get)
|
||||||
|
|
||||||
If Header(#http_head_request) = "/"
|
;*
|
||||||
thread_requested = default_file
|
;* Detect websocket upgrade request
|
||||||
Else
|
;*
|
||||||
thread_requested = Header(#http_head_request)
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
ldl::Logging("Requested:"+thread_requested)
|
If LCase(Header(lhs_web_helper::#http_head_connection)) = lhs_web_helper::#http_connection_upgrade
|
||||||
ToCallType = call_request(Host_call + thread_requested, #get_handler_prototype)
|
;Whe have a Upgrade Request.
|
||||||
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get
|
;Current Disconnect it with not supported
|
||||||
ToCall = call_request(Host_call + thread_requested)
|
response_status = lhs_web_helper::#http_state_501
|
||||||
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0
|
thread_type = lhs_web_helper::mimetype("html")
|
||||||
LibraryToCall = call_request_string(Host_call + thread_requested, #get_handler_library_perm)
|
thread_temp_cache_memory = AllocateMemory(StringByteLength("Unsuported"))
|
||||||
If Len(LibraryToCall) > 0
|
PokeS(thread_temp_cache_memory, "Unsuported")
|
||||||
Library_ID = OpenLibrary(#PB_Any, LibraryToCall)
|
thread_data_size = StringByteLength("Unsuported")
|
||||||
If Library_ID
|
If response_status = "" ;Remove if finished...
|
||||||
|
;detect a route to there.
|
||||||
|
If Left(Header(#http_head_request),2) = "ws"
|
||||||
|
;Whe have a websocket request.
|
||||||
|
;Detect if whe have a library who react to there:
|
||||||
|
ToCallType = call_request(Host_call + thread_requested, #get_handler_prototype)
|
||||||
|
If ToCallType = #handler_proto_i_get Or ToCallType = #handler_proto_get
|
||||||
|
|
||||||
Else
|
|
||||||
ldl::Logging("Library could not be opened")
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
Else
|
Else
|
||||||
ToCall = 0
|
|
||||||
EndIf
|
If Header(#http_head_request) = "/"
|
||||||
If ToCall = 0
|
|
||||||
If Right(thread_requested,1) = "/"
|
|
||||||
thread_requested = default_file
|
thread_requested = default_file
|
||||||
Else
|
Else
|
||||||
thread_requested = thread_requested
|
thread_requested = Header(#http_head_request)
|
||||||
EndIf
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
If ToCall > 0 ;Dann ist eine Funktion hinterlegt und zulässig aufgerufen zu werden.
|
|
||||||
;{ Dynamischer WebHandler
|
|
||||||
Handler_Response = call_function(ToCallType, ToCall, Header())
|
|
||||||
|
|
||||||
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0 And Library_ID <> 0
|
|
||||||
CloseLibrary(Library_ID)
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
ldl::Logging("Main Client Response :"+Handler_Response)
|
ldl::Logging("Requested:"+thread_requested)
|
||||||
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
ToCallType = call_request(Host_call + thread_requested, #get_handler_prototype)
|
||||||
If MyThreadJSON
|
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get Or ToCallType = #handler_proto_i_universal Or ToCallType = #handler_proto_i_get
|
||||||
ClearMap(Response())
|
ToCall = call_request(Host_call + thread_requested)
|
||||||
ExtractJSONMap(JSONValue(MyThreadJSON), Response())
|
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0
|
||||||
FreeJSON(MyThreadJSON)
|
LibraryToCall = call_request_string(Host_call + thread_requested, #get_handler_library_perm)
|
||||||
Else
|
If Len(LibraryToCall) > 0
|
||||||
;WTF ???
|
Library_ID = OpenLibrary(#PB_Any, LibraryToCall)
|
||||||
ldl::Logging("Fehler Absturz")
|
If Library_ID
|
||||||
Break 2 ; Thread abschiessen
|
|
||||||
EndIf
|
|
||||||
ldl::Logging("Response Content:"+Response(#cha_R_ResponseContentType))
|
|
||||||
Select Response(#cha_R_ResponseContentType)
|
|
||||||
Case #response_Memory
|
|
||||||
ldl::Logging("Response Memory")
|
|
||||||
thread_data_size = Val(Response(#cha_R_MemorySize))
|
|
||||||
thread_temp_cache_memory = Val(Response(#cha_R_MemoryAdress))
|
|
||||||
thread_type = Response(#cha_R_ResponseType)
|
|
||||||
Case #response_string
|
|
||||||
ldl::Logging("Response String")
|
|
||||||
thread_temp_decode_memory = AllocateMemory(StringByteLength(Response(#cha_R_StringBase64)))
|
|
||||||
thread_data_size = Base64Decoder(Response(#cha_R_StringBase64), thread_temp_decode_memory, StringByteLength(Response(#cha_R_StringBase64)))
|
|
||||||
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
|
||||||
CopyMemory(thread_temp_decode_memory, thread_temp_cache_memory, thread_data_size)
|
|
||||||
FreeMemory(thread_temp_decode_memory)
|
|
||||||
thread_type = Response(#cha_R_ResponseType)
|
|
||||||
Default
|
|
||||||
;Solte ja nicht passieren.
|
|
||||||
EndSelect
|
|
||||||
ldl::Logging("Content Finished")
|
|
||||||
;}
|
|
||||||
|
|
||||||
; ElseIf configuration\cache\enable = 1
|
Else
|
||||||
; ;{ Cached File Handling BUGGY!!!!!!!
|
ldl::Logging("Library could not be opened")
|
||||||
; thread_temp_cache_memory = AllocateMemory(1024)
|
|
||||||
; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory)
|
|
||||||
; If thread_temp_cache = #error_string
|
|
||||||
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
|
|
||||||
;
|
|
||||||
; If thread_file_handle
|
|
||||||
; ;Alles Ok
|
|
||||||
; Else
|
|
||||||
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead)
|
|
||||||
; ldl::Logging("FileDir:" + configuration\basedir + configuration\defaultfile)
|
|
||||||
; If Not thread_file_handle
|
|
||||||
; thread_file_handle = ReadFile(#PB_Any, "error.html")
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; EndIf
|
|
||||||
; thread_data_size = Lof(thread_file_handle)
|
|
||||||
; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size)
|
|
||||||
; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size)
|
|
||||||
; CloseFile(thread_file_handle)
|
|
||||||
; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size)
|
|
||||||
;
|
|
||||||
; Else
|
|
||||||
; thread_data_size = Val(StringField(thread_temp_cache, 1, ":"))
|
|
||||||
; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":"))
|
|
||||||
; EndIf
|
|
||||||
; ;}
|
|
||||||
|
|
||||||
Else
|
|
||||||
;{ Uncached file sems to be stable tested up to 200 clients and 100 requests.
|
|
||||||
If file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id) = thread_requested
|
|
||||||
thread_file_handle = ReadFile(#PB_Any, home_dir + thread_requested,#PB_File_SharedRead)
|
|
||||||
If Not thread_file_handle
|
|
||||||
thread_file_handle = ReadFile(#PB_Any, home_dir + default_file ,#PB_File_SharedRead)
|
|
||||||
ldl::Logging("FileDir:" + home_dir + default_file, ErrorLog)
|
|
||||||
If Not thread_file_handle
|
|
||||||
ldl::Logging("Error file set", ErrorLog)
|
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
thread_data_size = Lof(thread_file_handle)
|
|
||||||
; Is File bigger than MaxFileSize in Memory allowed ?
|
|
||||||
If thread_data_size >= configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize
|
|
||||||
;Do Handle the File another way.
|
|
||||||
thread_temp_cache_memory = AllocateMemory(configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize)
|
|
||||||
thread_temp_file_readed = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\DefaultBlockSize
|
|
||||||
thread_data_readed = ReadData(thread_file_handle, thread_temp_cache_memory, thread_temp_file_readed)
|
|
||||||
thread_data_to_read = thread_data_size - thread_data_readed
|
|
||||||
thread_oversized_file = #True
|
|
||||||
Else
|
|
||||||
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
|
||||||
ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size)
|
|
||||||
CloseFile(thread_file_handle)
|
|
||||||
thread_oversized_file = #False
|
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
thread_redirect = #True
|
ToCall = 0
|
||||||
|
EndIf
|
||||||
|
If ToCall = 0
|
||||||
|
If Right(thread_requested,1) = "/"
|
||||||
|
thread_requested = default_file
|
||||||
|
Else
|
||||||
|
thread_requested = thread_requested
|
||||||
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
;}
|
If ToCall > 0 ;Dann ist eine Funktion hinterlegt und zulässig aufgerufen zu werden.
|
||||||
|
;{ Dynamischer WebHandler
|
||||||
|
Handler_Response = call_function(ToCallType, ToCall, Header())
|
||||||
|
|
||||||
|
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0 And Library_ID <> 0
|
||||||
|
CloseLibrary(Library_ID)
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
ldl::Logging("Main Client Response :"+Handler_Response)
|
||||||
|
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
||||||
|
If MyThreadJSON
|
||||||
|
ClearMap(Response())
|
||||||
|
ExtractJSONMap(JSONValue(MyThreadJSON), Response())
|
||||||
|
FreeJSON(MyThreadJSON)
|
||||||
|
Else
|
||||||
|
;WTF ???
|
||||||
|
ldl::Logging("Fehler Absturz")
|
||||||
|
Break 2 ; Thread abschiessen
|
||||||
|
EndIf
|
||||||
|
ldl::Logging("Response Content:"+Response(#cha_R_ResponseContentType))
|
||||||
|
Select Response(#cha_R_ResponseContentType)
|
||||||
|
Case #response_Memory
|
||||||
|
ldl::Logging("Response Memory")
|
||||||
|
thread_data_size = Val(Response(#cha_R_MemorySize))
|
||||||
|
thread_temp_cache_memory = Val(Response(#cha_R_MemoryAdress))
|
||||||
|
thread_type = Response(#cha_R_ResponseType)
|
||||||
|
Case #response_string
|
||||||
|
ldl::Logging("Response String")
|
||||||
|
thread_temp_decode_memory = AllocateMemory(StringByteLength(Response(#cha_R_StringBase64)))
|
||||||
|
thread_data_size = Base64Decoder(Response(#cha_R_StringBase64), thread_temp_decode_memory, StringByteLength(Response(#cha_R_StringBase64)))
|
||||||
|
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
||||||
|
CopyMemory(thread_temp_decode_memory, thread_temp_cache_memory, thread_data_size)
|
||||||
|
FreeMemory(thread_temp_decode_memory)
|
||||||
|
thread_type = Response(#cha_R_ResponseType)
|
||||||
|
Default
|
||||||
|
;Solte ja nicht passieren.
|
||||||
|
EndSelect
|
||||||
|
ldl::Logging("Content Finished")
|
||||||
|
;}
|
||||||
|
|
||||||
|
; ElseIf configuration\cache\enable = 1
|
||||||
|
; ;{ Cached File Handling BUGGY!!!!!!!
|
||||||
|
; thread_temp_cache_memory = AllocateMemory(1024)
|
||||||
|
; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory)
|
||||||
|
; If thread_temp_cache = #error_string
|
||||||
|
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
|
||||||
|
;
|
||||||
|
; If thread_file_handle
|
||||||
|
; ;Alles Ok
|
||||||
|
; Else
|
||||||
|
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead)
|
||||||
|
; ldl::Logging("FileDir:" + configuration\basedir + configuration\defaultfile)
|
||||||
|
; If Not thread_file_handle
|
||||||
|
; thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
|
; EndIf
|
||||||
|
;
|
||||||
|
; EndIf
|
||||||
|
; thread_data_size = Lof(thread_file_handle)
|
||||||
|
; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size)
|
||||||
|
; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size)
|
||||||
|
; CloseFile(thread_file_handle)
|
||||||
|
; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size)
|
||||||
|
;
|
||||||
|
; Else
|
||||||
|
; thread_data_size = Val(StringField(thread_temp_cache, 1, ":"))
|
||||||
|
; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":"))
|
||||||
|
; EndIf
|
||||||
|
; ;}
|
||||||
|
|
||||||
|
Else
|
||||||
|
;{ Uncached file sems to be stable tested up to 200 clients and 100 requests.
|
||||||
|
If file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id) = thread_requested
|
||||||
|
thread_file_handle = ReadFile(#PB_Any, home_dir + thread_requested,#PB_File_SharedRead)
|
||||||
|
If Not thread_file_handle
|
||||||
|
thread_file_handle = ReadFile(#PB_Any, home_dir + default_file ,#PB_File_SharedRead)
|
||||||
|
ldl::Logging("FileDir:" + home_dir + default_file, ErrorLog)
|
||||||
|
If Not thread_file_handle
|
||||||
|
ldl::Logging("Error file set", ErrorLog)
|
||||||
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
thread_data_size = Lof(thread_file_handle)
|
||||||
|
; Is File bigger than MaxFileSize in Memory allowed ?
|
||||||
|
If thread_data_size >= configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize
|
||||||
|
;Do Handle the File another way.
|
||||||
|
thread_temp_cache_memory = AllocateMemory(configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize)
|
||||||
|
thread_temp_file_readed = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\DefaultBlockSize
|
||||||
|
thread_data_readed = ReadData(thread_file_handle, thread_temp_cache_memory, thread_temp_file_readed)
|
||||||
|
thread_data_to_read = thread_data_size - thread_data_readed
|
||||||
|
thread_oversized_file = #True
|
||||||
|
Else
|
||||||
|
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
||||||
|
ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size)
|
||||||
|
CloseFile(thread_file_handle)
|
||||||
|
thread_oversized_file = #False
|
||||||
|
EndIf
|
||||||
|
Else
|
||||||
|
thread_redirect = #True
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
;}
|
||||||
|
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
|
||||||
EndIf
|
|
||||||
;}
|
;}
|
||||||
Case #http_method_post
|
Case #http_method_post
|
||||||
|
|
||||||
|
@ -859,7 +891,7 @@ Module lhs_web
|
||||||
EndIf
|
EndIf
|
||||||
ldl::Logging("Requested:"+thread_requested)
|
ldl::Logging("Requested:"+thread_requested)
|
||||||
ToCallType = call_request(Host_call+thread_requested, #get_handler_prototype)
|
ToCallType = call_request(Host_call+thread_requested, #get_handler_prototype)
|
||||||
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_post
|
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_post Or ToCallType = #handler_proto_i_universal Or ToCallType = #handler_proto_i_post
|
||||||
ToCall = call_request(Host_call + thread_requested)
|
ToCall = call_request(Host_call + thread_requested)
|
||||||
ldl::Logging("A To Call is found:"+Str(ToCall))
|
ldl::Logging("A To Call is found:"+Str(ToCall))
|
||||||
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0
|
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0
|
||||||
|
|
Loading…
Reference in a new issue