Initial Websocket and Bugfix for prototype support

This commit is contained in:
René Linder 2023-03-31 10:40:32 +02:00
parent 194245d3b6
commit 8574b29021

View file

@ -677,6 +677,36 @@ Module lhs_web
;{ ;{
ldl::Logging(#http_method_get) ldl::Logging(#http_method_get)
;*
;* Detect websocket upgrade request
;*
If LCase(Header(lhs_web_helper::#http_head_connection)) = lhs_web_helper::#http_connection_upgrade
;Whe have a Upgrade Request.
;Current Disconnect it with not supported
response_status = lhs_web_helper::#http_state_501
thread_type = lhs_web_helper::mimetype("html")
thread_temp_cache_memory = AllocateMemory(StringByteLength("Unsuported"))
PokeS(thread_temp_cache_memory, "Unsuported")
thread_data_size = StringByteLength("Unsuported")
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
EndIf
EndIf
EndIf
Else
If Header(#http_head_request) = "/" If Header(#http_head_request) = "/"
thread_requested = default_file thread_requested = default_file
Else Else
@ -685,7 +715,7 @@ Module lhs_web
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_get If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get Or ToCallType = #handler_proto_i_universal Or ToCallType = #handler_proto_i_get
ToCall = call_request(Host_call + thread_requested) ToCall = call_request(Host_call + thread_requested)
If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0 If call_request(Host_call + thread_requested, #get_handler_library_perm) = 0
LibraryToCall = call_request_string(Host_call + thread_requested, #get_handler_library_perm) LibraryToCall = call_request_string(Host_call + thread_requested, #get_handler_library_perm)
@ -749,34 +779,34 @@ Module lhs_web
ldl::Logging("Content Finished") ldl::Logging("Content Finished")
;} ;}
; ElseIf configuration\cache\enable = 1 ; ElseIf configuration\cache\enable = 1
; ;{ Cached File Handling BUGGY!!!!!!! ; ;{ Cached File Handling BUGGY!!!!!!!
; thread_temp_cache_memory = AllocateMemory(1024) ; thread_temp_cache_memory = AllocateMemory(1024)
; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory) ; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory)
; If thread_temp_cache = #error_string ; If thread_temp_cache = #error_string
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) ; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
; ;
; If thread_file_handle ; If thread_file_handle
; ;Alles Ok ; ;Alles Ok
; Else ; Else
; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) ; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead)
; ldl::Logging("FileDir:" + configuration\basedir + configuration\defaultfile) ; ldl::Logging("FileDir:" + configuration\basedir + configuration\defaultfile)
; If Not thread_file_handle ; If Not thread_file_handle
; thread_file_handle = ReadFile(#PB_Any, "error.html") ; thread_file_handle = ReadFile(#PB_Any, "error.html")
; EndIf ; EndIf
; ;
; EndIf ; EndIf
; thread_data_size = Lof(thread_file_handle) ; thread_data_size = Lof(thread_file_handle)
; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size) ; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size)
; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size) ; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size)
; CloseFile(thread_file_handle) ; CloseFile(thread_file_handle)
; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size) ; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size)
; ;
; Else ; Else
; thread_data_size = Val(StringField(thread_temp_cache, 1, ":")) ; thread_data_size = Val(StringField(thread_temp_cache, 1, ":"))
; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":")) ; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":"))
; EndIf ; EndIf
; ;} ; ;}
Else Else
;{ Uncached file sems to be stable tested up to 200 clients and 100 requests. ;{ Uncached file sems to be stable tested up to 200 clients and 100 requests.
@ -812,6 +842,8 @@ Module lhs_web
;} ;}
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