Add first Cookie Header Work

This commit is contained in:
René Linder 2024-12-05 17:13:08 +01:00
parent bbeceee2b8
commit a705a62ad2
4 changed files with 69 additions and 31 deletions

View file

@ -109,6 +109,9 @@
Structure session
Cookie.s
TTL.q
KillTime.q
Daten.s
EndStructure
Structure host

View file

@ -701,13 +701,38 @@ Module lhs_web
EndIf
;TODO: Header Handler
; ex. Cookie: #http_head_cookie
; ex. Cookie: #http_head_cookie and #http_head_cookie_set
;TODO: Optimizing and change Cookie Session Handling.
ldl::Logging("Check {"+#http_head_cookie+"}:["+Header(#http_head_cookie)+"]")
If Header(#http_head_cookie) <> ""
ldl::Logging("Session:"+Header(#http_head_cookie))
If configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie))\KillTime >= Second(Date())
;Session Lifetime over?
ldl::Logging("Session TTL Over. Resetting.")
DeleteMapElement(configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(), Header(#http_head_cookie))
Header(#http_head_cookie_set) = CreateUUID()
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\Cookie = Header(#http_head_cookie_set)
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL = 3600
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\KillTime = Second(Date()) + configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL
ElseIf configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie))\Cookie = Header(#http_head_cookie)
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie))\KillTime = Second(Date()) + configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie))\TTL
Else
;Session unknown:
ldl::Logging("Session unknown. Resetting.")
Header(#http_head_cookie_set) = CreateUUID()
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\Cookie = Header(#http_head_cookie_set)
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL = 3600
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\KillTime = Second(Date()) + configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL
EndIf
Else
Header(#http_head_cookie) = CreateUUID()
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie))\Cookie = Header(#http_head_cookie)
ldl::Logging("No Cookie set .... Set one:")
Header(#http_head_cookie_set) = CreateUUID()
ldl::Logging("Set {"+#http_head_cookie_set+"}:["+Header(#http_head_cookie_set)+"]")
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\Cookie = Header(#http_head_cookie_set)
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL = 3600
configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\KillTime = Second(Date()) + configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\sessions(Header(#http_head_cookie_set))\TTL
EndIf
Select Header(#http_head_method)
@ -1074,6 +1099,7 @@ Module lhs_web
FormatDate("%hh:%ii:%ss GMT+1", Date())
ClearMap(Header())
If Response(#cha_R_http_head_status) <> ""
Header(#http_head_status) = Response(#cha_R_http_head_status)
ElseIf response_status <> ""
@ -1081,9 +1107,11 @@ Module lhs_web
Else
Header(#http_head_status) = status_get_header("200")
EndIf
If Response(#http_head_set_cookie) <> ""
Header(#http_head_set_cookie) = Response(#http_head_set_cookie)
If Response(#http_head_cookie) <> ""
Header(#http_head_cookie) = Response(#http_head_cookie)
EndIf
If thread_redirect = #True
Header(#http_head_redirect) = file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id)
;TODO: Verify it's a file or a configuration ...
@ -1102,7 +1130,8 @@ Module lhs_web
Header(#http_head_keep_alive) = "timeout=15, max=1000"
thread_header = http_header_generate(Header())
ldl::Logging("Header:"+thread_header)
ldl::Logging("Header:")
ldl::Logging(thread_header)
;large File Handling
If thread_redirect = #True
thread_buffer = AllocateMemory(StringByteLength(thread_header)+12)
@ -1115,6 +1144,11 @@ Module lhs_web
thread_buffer_offset = thread_buffer
thread_buffer_length = PokeS(thread_buffer_offset, thread_header,-1, #PB_UTF8|#PB_String_NoZero) : thread_buffer_offset + thread_buffer_length
ldl::Logging("Header Finished")
ldl::Logging("Header Map fields:")
ForEach(Header())
ldl::Logging("Field:["+MapKey(Header())+"] and content:["+Header()+"]")
Next
ldl::Logging("Header Map fields finished.")
EndIf
;Copy temporary File Buffer to normal Buffer.
If thread_temp_cache_memory <> 0 And thread_buffer_offset <> 0 And thread_data_size <> 0 And thread_oversized_file = #False And thread_redirect = #False
@ -1461,7 +1495,8 @@ Module lhs_web
Debug thread_requested
file_type = FileSize(configuration\hosts(hostid)\basedir + thread_requested)
If file_type = -1
thread_requested = "configuration\errorfile404"
thread_requested = "configuration\errorfile404" ;TODO: Change wrong File
ElseIf file_type = -2
;Is a Directory
If Right(thread_requested,1) = "/"

View file

@ -8,7 +8,7 @@
<section name="data">
<explorer view="../../../bin/purebasic/examples/" pattern="0"/>
<log show="1"/>
<lastopen date="2024-09-30 17:05" user="renlin" host="renlin-office"/>
<lastopen date="2024-10-18 07:07" user="renlin" host="renlin-office"/>
</section>
<section name="files">
<file name="build_tools/src/default_host_xml_export.pb">
@ -28,88 +28,88 @@
<fingerprint md5="a3c3072e4eb0a8d09d9e02b2d57b707d"/>
</file>
<file name="inc/lweb_header_privat.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="5" panelstate="+-"/>
<fingerprint md5="2803c98024b9588db6f85d77f30023e1"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="23" panelstate="+-"/>
<fingerprint md5="43e37e412a37cb233bfd64518cac7f04"/>
</file>
<file name="inc/lweb_helper.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="6" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="5" panelstate="+-"/>
<fingerprint md5="e6b5d486bd08b6de7f34a94316df2543"/>
</file>
<file name="lhs_lib/NET/lhs_web_helper.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="7" panelstate="+--"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="6" panelstate="+--"/>
<fingerprint md5="52ed1675b88a463b7ada8cf2003430e1"/>
</file>
<file name="inc/lweb_helper_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="8" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="7" panelstate="+-"/>
<fingerprint md5="6ea3e5baa62f8e66063e3b45e17d7e91"/>
</file>
<file name="inc/lweb_http.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="9" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="8" panelstate="+-"/>
<fingerprint md5="a42cddb6a1102779589facc17ba96cd8"/>
</file>
<file name="inc/lweb_http_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="10" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="9" panelstate="+-"/>
<fingerprint md5="d7df8e152291b0f91e8316ad8e00191c"/>
</file>
<file name="inc/lweb_http_status.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="11" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="10" panelstate="+-"/>
<fingerprint md5="6f3a4e08bf4318407b547cb5ca794260"/>
</file>
<file name="inc/lweb_http_status_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="12" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="11" panelstate="+-"/>
<fingerprint md5="6fd5131bd1dc2558e3abf2160fbef98c"/>
</file>
<file name="inc/lweb_http_status_header_private.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="13" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="12" panelstate="+-"/>
<fingerprint md5="c7736a7cdc87c1ed676b17d9757ba135"/>
</file>
<file name="inc/lweb_IP.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="14" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="13" panelstate="+-"/>
<fingerprint md5="502f26844f0a4b7d7f25924f76b17473"/>
</file>
<file name="inc/lweb_IP_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="15" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="14" panelstate="+-"/>
<fingerprint md5="636558037ff2cab03552fb129e2a4f52"/>
</file>
<file name="inc/lweb_server_cfg.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="16" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="15" panelstate="+-"/>
<fingerprint md5="4ef74f56126e4dcbb66e51ac1fe2d605"/>
</file>
<file name="inc/lweb_server_cfg_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="17" panelstate="+-"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="16" panelstate="+-"/>
<fingerprint md5="57787e1e3db6c77d81fc5576e124beae"/>
</file>
<file name="installation.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="18" panelstate="+"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="17" panelstate="+"/>
<fingerprint md5="b5ba175b6bddf19d7c039396199911fd"/>
</file>
<file name="lhs_lib/NET/lhs_net_socket.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="19" panelstate="+--"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="18" panelstate="+--"/>
<fingerprint md5="9fc8219dabd4ed47be5289b435d089d6"/>
</file>
<file name="lhs_lib/NET/lhs_net_tls.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="20" panelstate="+--"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="19" panelstate="+--"/>
<fingerprint md5="c586d25a1493f437c7461374a891a715"/>
</file>
<file name="lhs_lib/SYS/lhs_log_ext.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="21" panelstate="+--"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="20" panelstate="+--"/>
<fingerprint md5="f37e027dbab8be85535563b3287f7fff"/>
</file>
<file name="lhs_lib/SYS/lhs_sys_debug_wrapper.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="22" panelstate="+--"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="21" panelstate="+--"/>
<fingerprint md5="8c3a929cf403d443ec968d21593294a5"/>
</file>
<file name="lhttpd.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="23" panelstate="+"/>
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="22" panelstate="+"/>
<fingerprint md5="f24daf76ff093910b9f4fb635d2a439c"/>
</file>
<file name="lweb.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="24" panelstate="+"/>
<fingerprint md5="c1c977e77f83f79bc4e6e2b64b0a6b77"/>
<fingerprint md5="5082cb76051665b931fd3a36a5b273e7"/>
</file>
<file name="lweb_header.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="25" panelstate="+"/>
<fingerprint md5="53bf42c3a6e95d381fa49bc2d076946b"/>
<fingerprint md5="a1dd35af779a1e458e16d58665eb83a8"/>
</file>
<file name="server_example.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="26" panelstate="+"/>

View file

@ -100,7 +100,7 @@ DeclareModule lhs_web
#http_head_connection = "connection:"
#http_head_keep_alive = "keep-alive:"
#http_head_cookie = "cookie:"
#http_head_set_cookie = "set-cookie:"
#http_head_cookie_set = "set-cookie:"
#http_head_redirect = "location:"
#http_content_type_application_x_www_form_urlencoded = "application/x-www-form-urlencoded"