@@ -64,10 +64,18 @@ sync-op: func [port body /local state] [
64
64
;--Richard
65
65
while [not find [ready close] state/state ][
66
66
;@@net-log ["########### sync-op.." state/state]
67
- unless port? wait [state/connection port/spec/timeout ] [http-error "Timeout" ]
67
+ unless port? wait [state/connection port/spec/timeout ] [http-error "HTTP(s) Timeout" ]
68
68
;@@net-log ["########### sync-op wakeup" state/state]
69
69
switch state/state [
70
+ inited [
71
+ ;@@net-log ["state/connection open? ->" open? state/connection]
72
+ if not open? state/connection [
73
+ state/error: make-http-error rejoin ["Internal " state/connection/spec/ref " connection closed" ]
74
+ break
75
+ ]
76
+ ]
70
77
reading-data [
78
+ ;? state/connection
71
79
read state/connection
72
80
]
73
81
redirect [
@@ -77,6 +85,7 @@ sync-op: func [port body /local state] [
77
85
]
78
86
]
79
87
]
88
+ if state/error [do state/error ]
80
89
body: copy port
81
90
if state/close? [close port]
82
91
body
@@ -136,6 +145,7 @@ http-awake: func [event /local port http-port state awake res] [
136
145
awake make event! [type: 'connect port: http-port]
137
146
]
138
147
close [
148
+ ;?? state/state
139
149
res: switch state/state [
140
150
ready [
141
151
awake make event! [type: 'close port: http-port]
@@ -263,13 +273,16 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
263
273
]
264
274
] [
265
275
info/response-line: line: to string! copy/part conn/data d1
276
+ ;?? line
266
277
info/headers: headers: construct /with d1 http-response-headers
267
278
info/name: spec/ref
268
279
if headers/content-length [info/size: headers/content-length: to integer! headers/content-length ]
269
280
if headers/last-modified [info/date: attempt [idate-to-date headers/last-modified ]]
270
281
remove/part conn/data d2
271
282
state/state: 'reading-data
272
283
]
284
+ ;? state
285
+ ;?? headers
273
286
unless headers [
274
287
read conn
275
288
return false
@@ -317,6 +330,8 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
317
330
unless res [res: awake make event! [type: 'ready port: port]]
318
331
] [
319
332
res: check-data port
333
+ ;?? res
334
+ ;?? state/state
320
335
if all [not res state/state = 'ready] [
321
336
res: awake make event! [type: 'done port: port]
322
337
unless res [res: awake make event! [type: 'ready port: port]]
@@ -455,6 +470,7 @@ check-data: func [port /local headers res data out chunk-size mk1 mk2 trailer st
455
470
res: false
456
471
457
472
;@@net-log ["[HTTP check-data] bytes:" length? conn/data]
473
+ ;? conn
458
474
459
475
case [
460
476
headers/transfer-encoding = "chunked" [
@@ -577,7 +593,7 @@ sys/make-scheme [
577
593
port [port! ]
578
594
/local conn
579
595
] [
580
- ;@@net-log ["[HTTP open]" port/state]
596
+ ;@@net-log ["[HTTP open] state: " port/state]
581
597
if port/state [return port]
582
598
if none? port/spec/host [http-error "Missing host address" ]
583
599
port/state: context [
@@ -588,6 +604,7 @@ sys/make-scheme [
588
604
info: make port/scheme/info [type: 'url]
589
605
awake: : port/awake
590
606
]
607
+ ;? port/state/info
591
608
port/state/connection: conn: make port! compose [
592
609
scheme: (to lit-word! either port/spec/scheme = 'http ['tcp]['tls])
593
610
host: port/spec/host
@@ -597,7 +614,7 @@ sys/make-scheme [
597
614
;?? conn
598
615
conn/awake: :http-awake
599
616
conn/locals: port
600
- ;@@net-log ["[HTTP opne] " conn/spec/scheme conn/spec/host]
617
+ ;@@net-log ["[HTTP open] scheme: " conn/spec/scheme conn/spec/host]
601
618
;?? conn
602
619
open conn
603
620
port
0 commit comments