Skip to content

Commit

Permalink
prepare for ok/fail HTTP responses
Browse files Browse the repository at this point in the history
  • Loading branch information
dalnefre committed Jan 29, 2025
1 parent cb645ba commit a072b87
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 11 deletions.
81 changes: 76 additions & 5 deletions apps/www/static.asm
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ boot: ; _ <- {caps}
; Select next stage

msg 0 ; {caps}
push stage_1 ; {caps} stage
push stage_0 ; {caps} stage
; push stage_1 ; {caps} stage
; push stage_9 ; {caps} stage
actor become ; --

; Initialize test request-blob
; Initialize test get-request blob

push http.get_req ; list=get_req
actor self ; list cust=SELF
Expand All @@ -115,6 +116,64 @@ boot: ; _ <- {caps}
actor create ; cust,list init.blob_dev
ref std.send_msg

stage_0: ; {caps} <- blob
state 0 ; {caps}
msg 0 ; {caps} get_req_blob
pair 1 ; get_req_blob,{caps}
push stage_0a ; get_req_blob,{caps} stage_0a
actor become ; --

; Initialize test fail-response blob

push http.not_found_rsp ; list=not_found_rsp
actor self ; list cust=SELF
pair 1 ; cust,list
state 0 ; cust,list {caps}
push dev.blob_key ; cust,list {caps} blob_key
dict get ; cust,list blob_dev
push blob.init ; cust,list blob_dev init
actor create ; cust,list init.blob_dev
ref std.send_msg

stage_0a: ; get_req_blob,{caps} <- blob
state 0 ; get_req_blob,{caps}
msg 0 ; get_req_blob,{caps} fail_rsp_blob
pair 1 ; fail_rsp_blob,get_req_blob,{caps}
push stage_0b ; fail_rsp_blob,get_req_blob,{caps} stage_0b
actor become ; --

; Initialize test ok-response blob

push http.ok_rsp ; list=ok_rsp
actor self ; list cust=SELF
pair 1 ; cust,list
state 0 ; cust,list {caps}
push dev.blob_key ; cust,list {caps} blob_key
dict get ; cust,list blob_dev
push blob.init ; cust,list blob_dev init
actor create ; cust,list init.blob_dev
ref std.send_msg

stage_0b: ; fail_rsp_blob,get_req_blob,{caps} <- blob
state 0 ; fail_rsp_blob,get_req_blob,{caps}
msg 0 ; fail_rsp_blob,get_req_blob,{caps} ok_rsp_blob
pair 1 ; ok_rsp_blob,fail_rsp_blob,get_req_blob,{caps}
push stage_0c ; ok_rsp_blob,fail_rsp_blob,get_req_blob,{caps} stage_0c
actor become ; --

push #? ; _
actor self ; _ SELF
ref std.send_msg

stage_0c: ; ok_rsp_blob,fail_rsp_blob,get_req_blob,{caps} <- blob
state -3 ; {caps}
push stage_1 ; {caps} stage_1
actor become ; --

state 3 ; get_req_blob
actor self ; get_req_blob SELF
ref std.send_msg

stage_1: ; {caps} <- blob
state 0 ; {caps}
push stage_1a ; {caps} stage_1a
Expand Down Expand Up @@ -209,7 +268,7 @@ stage_2: ; {caps} <- blob

stage_2a: ; {caps} <- base,len,blob
state 0 ; {caps}
push stage_8 ; {caps} stage_8
push stage_3 ; {caps} stage_3
actor become ; --

; Attempt to match the requested "path" token
Expand All @@ -223,9 +282,9 @@ stage_2a: ; {caps} <- base,len,blob
call new_token_ptrn ; cust,ofs,blob ptrn
ref std.send_msg

stage_8: ; {caps} <- base,len,blob
stage_3: ; {caps} <- base,len,blob
state 0 ; {caps}
push stage_9 ; {caps} stage_9
push stage_4 ; {caps} stage_4
actor become ; --

; Report PEG parser results
Expand All @@ -244,6 +303,18 @@ stage_8: ; {caps} <- base,len,blob
actor self ; blob' SELF
ref std.send_msg

stage_4: ; {caps} <- blob
state 0 ; {caps}
push stage_9 ; {caps} stage_9
actor become ; --

; Forward blob to next stage
; [TODO: create response from "path" blob]

msg 0 ; blob
actor self ; blob SELF
ref std.send_msg

stage_9: ; {caps} <- blob

; Select display strategy for blob
Expand Down
34 changes: 28 additions & 6 deletions lib/http_data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ not_found_rsp:
pair_t '\n'
rsp_hdrs:
;; Content-Type: text/plain
pair_t 'C'
pair_t 'C' ; offset=24
pair_t 'o'
pair_t 'n'
pair_t 't'
Expand All @@ -100,7 +100,7 @@ rsp_hdrs:
pair_t 'e'
pair_t ':'
pair_t ' '
pair_t 't'
pair_t 't' ; offset=38
pair_t 'e'
pair_t 'x'
pair_t 't'
Expand All @@ -113,7 +113,7 @@ rsp_hdrs:
pair_t '\r'
pair_t '\n'
;; Content-Length: 11
pair_t 'C'
pair_t 'C' ; offset=50
pair_t 'o'
pair_t 'n'
pair_t 't'
Expand All @@ -129,7 +129,7 @@ rsp_hdrs:
pair_t 'h'
pair_t ':'
pair_t ' '
pair_t '1'
pair_t '1' ; offset=66
pair_t '1'
pair_t '\r'
pair_t '\n'
Expand All @@ -138,7 +138,7 @@ rsp_hdrs:
pair_t '\n'
content:
;; Not Found
pair_t 'N'
pair_t 'N' ; offset=72
pair_t 'o'
pair_t 't'
pair_t ' '
Expand All @@ -147,7 +147,28 @@ content:
pair_t 'u'
pair_t 'n'
pair_t 'd'
ref crlf
ref crlf ; offset=81

ok_rsp:
;; HTTP/1.0 200 OK
pair_t 'H'
pair_t 'T'
pair_t 'T'
pair_t 'P'
pair_t '/'
pair_t '1'
pair_t '.'
pair_t '0'
pair_t ' '
pair_t '2'
pair_t '0'
pair_t '0'
pair_t ' '
pair_t 'O'
pair_t 'K'
pair_t '\r'
pair_t '\n'
ref rsp_hdrs ; offset=17

.export
get_req
Expand All @@ -158,3 +179,4 @@ content:
not_found_rsp
rsp_hdrs
content
ok_rsp

0 comments on commit a072b87

Please sign in to comment.