Skip to content

Commit

Permalink
add http server body callback
Browse files Browse the repository at this point in the history
  • Loading branch information
salhk committed Jul 16, 2024
1 parent 4d8d6f4 commit d03aac3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions http_server/http_server.tbh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type http_server_state
request_header_end as string(4)
request_authenticated as boolean
request_length as dword
request_read_pos as dword
resp_buf as string
file_size as dword
file_pos as dword
Expand All @@ -53,6 +54,7 @@ declare sub http_server_response_status(code as word)
declare sub http_server_response_header(byref header as string(50), byref value as string)
declare sub http_server_response_header_end()
declare sub callback_http_server_header_received(byref server as http_server_state, byref header as string, byref value as string)
declare sub callback_http_server_body_received(byref server as http_server_state, byref body as string)
declare function callback_http_server_endpoint_called(byref server as http_server_state) as boolean
declare function http_server_decode(byref encoded_string as string) as string
declare function http_server_find_param(byref http_req_string as string, byref argument as string) as string
7 changes: 5 additions & 2 deletions http_server/http_server.tbs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,14 @@ sub http_server_proc_sock_data()
http_servers(index).request_header_name=""
http_servers(index).request_value_buffer=""
http_servers(index).request_header_end=""
http_servers(index).request_read_pos=0
end if
case HTTP_SERVER_STATE_RQ_BODY
http_servers(index).request_value_buffer=http_servers(index).request_value_buffer+mid(data,ci,255)
http_servers(index).request_value_buffer=http_servers(index).request_value_buffer+mid(data,ci,len(data)-ci+1)
http_servers(index).request_read_pos=http_servers(index).request_read_pos+len(data)-ci+1
callback_http_server_body_received(http_servers(index),mid(data,ci,len(data)-ci))
ci=len(data)
if len(http_servers(index).request_value_buffer)>=http_servers(index).request_length then
if http_servers(index).request_read_pos>=http_servers(index).request_length then
http_servers(index).state=HTTP_SERVER_STATE_RS_HEADER
http_server_send_response_header(index)
end if
Expand Down

0 comments on commit d03aac3

Please sign in to comment.