@@ -31,7 +31,7 @@ REBOL [
31
31
]
32
32
]
33
33
34
- sync-op : func [ port body /local state encoding content-type code-page tmp] [
34
+ sync-op : func [ port body /local state encoding content-type code-page tmp] [
35
35
unless port/state [open port port/state/close?: yes]
36
36
state: port/state
37
37
state/awake: :read-sync-awake
@@ -41,7 +41,7 @@ sync-op: func [port body /local state encoding content-type code-page tmp] [
41
41
;The timeout should be triggered only when the response from other side exceeds the timeout value.
42
42
;--Richard
43
43
while [not find [ready close] state/state ][
44
- unless port? wait [state/connection port/spec/timeout ] [
44
+ unless port? wait [state/connection port/spec/timeout ][
45
45
state/error: make-http-error "HTTP(s) Timeout"
46
46
break
47
47
]
@@ -104,7 +104,7 @@ sync-op: func [port body /local state encoding content-type code-page tmp] [
104
104
]
105
105
body
106
106
]
107
- read-sync-awake : func [ event [event! ] /local error] [
107
+ read-sync-awake : func [ event [event! ] /local error] [
108
108
sys/log/debug 'HTTP ["read-sync-awake:" event/type ]
109
109
switch /default event/type [
110
110
connect ready [
@@ -118,7 +118,7 @@ read-sync-awake: func [event [event!] /local error] [
118
118
true
119
119
]
120
120
custom [
121
- if all [event/offset event/offset/x = 300 ] [
121
+ if all [event/offset event/offset/x = 300 ][
122
122
event/port/state/state: 'redirect
123
123
return true
124
124
]
@@ -133,11 +133,11 @@ read-sync-awake: func [event [event!] /local error] [
133
133
]
134
134
if error? error [do error]
135
135
]
136
- ] [
136
+ ][
137
137
false
138
138
]
139
139
]
140
- http-awake : func [ event /local port http-port state awake res] [
140
+ http-awake : func [ event /local port http-port state awake res] [
141
141
port: event/port
142
142
http-port: port/locals
143
143
state: http-port/state
@@ -174,10 +174,10 @@ http-awake: func [event /local port http-port state awake res] [
174
174
awake make event! [type: 'error port: http-port]
175
175
]
176
176
reading-data [
177
- either any [integer? state/info/headers/content-length state/info/headers/transfer-encoding = "chunked" ] [
177
+ either any [integer? state/info/headers/content-length state/info/headers/transfer-encoding = "chunked" ][
178
178
state/error: make-http-error "Server closed connection"
179
179
awake make event! [type: 'error port: http-port]
180
- ] [
180
+ ][
181
181
;set state to CLOSE so the WAIT loop in 'sync-op can be interrupted --Richard
182
182
state/state: 'close
183
183
any [
@@ -192,12 +192,12 @@ http-awake: func [event /local port http-port state awake res] [
192
192
if error? state/error [ do state/error ]
193
193
res
194
194
]
195
- ] [true]
195
+ ][true]
196
196
]
197
197
make-http-error : func [
198
198
"Make an error for the HTTP protocol"
199
199
message [string! block! ]
200
- ] [
200
+ ] [
201
201
if block? message [message: ajoin message]
202
202
make error! [
203
203
type: 'Access
@@ -213,10 +213,10 @@ make-http-request: func [
213
213
headers [block! ] "Request headers (set-word! string! pairs)"
214
214
content [any-string! binary! none! ] {Request contents (Content-Length is created automatically). Empty string not exactly like none.}
215
215
/local result
216
- ] [
216
+ ] [
217
217
result: rejoin [
218
218
uppercase form method #" "
219
- either file? target [next mold target] [target]
219
+ either file? target [next mold target][target]
220
220
" HTTP/1.1" CRLF
221
221
]
222
222
foreach [word string] headers [
@@ -237,7 +237,7 @@ do-request: func [
237
237
"Perform an HTTP request"
238
238
port [port! ]
239
239
/local spec info
240
- ] [
240
+ ] [
241
241
spec: port/spec
242
242
info: port/state/info
243
243
spec/headers: body-of make make object! [
@@ -246,7 +246,7 @@ do-request: func [
246
246
Accept-Encoding: "gzip,deflate"
247
247
Host: either not find [80 443 ] spec/port-id [
248
248
rejoin [form spec/host #":" spec/port-id ]
249
- ] [
249
+ ][
250
250
form spec/host
251
251
]
252
252
User-Agent: any [system/schemes/http/User-Agent "REBOL" ]
@@ -259,13 +259,13 @@ do-request: func [
259
259
260
260
write port/state/connection make-http-request spec/method enhex any [spec/path %/ ] spec/headers spec/content
261
261
]
262
- parse-write-dialect : func [ port block /local spec] [
262
+ parse-write-dialect : func [ port block /local spec] [
263
263
spec: port/spec
264
264
parse block [[set block word! (spec/method: block) | (spec/method: 'POST)]
265
- opt [set block [file! | url! ] (spec/path: block)] [set block block! (spec/headers: block) | (spec/headers: [])] [set block [any-string! | binary! ] (spec/content: block) | (spec/content: none)]
265
+ opt [set block [file! | url! ] (spec/path: block)][set block block! (spec/headers: block) | (spec/headers: [])][set block [any-string! | binary! ] (spec/content: block) | (spec/content: none)]
266
266
]
267
267
]
268
- check-response : func [ port /local conn res headers d1 d2 line info state awake spec] [
268
+ check-response : func [ port /local conn res headers d1 d2 line info state awake spec] [
269
269
state: port/state
270
270
conn: state/connection
271
271
info: state/info
@@ -288,7 +288,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
288
288
sys/log/debug 'HTML "server using malformed line separator of #{0A0A}"
289
289
]
290
290
]
291
- ] [
291
+ ][
292
292
info/response-line: line: to string! copy/part conn/data d1
293
293
sys/log/more 'HTTP line
294
294
;probe to-string copy/part d1 d2
@@ -356,11 +356,11 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
356
356
state/state: 'ready
357
357
res: awake make event! [type: 'done port: port]
358
358
unless res [res: awake make event! [type: 'ready port: port]]
359
- ] [
359
+ ][
360
360
res: check-data port
361
361
;?? res
362
362
;?? state/state
363
- if all [not res state/state = 'ready] [
363
+ if all [not res state/state = 'ready][
364
364
res: awake make event! [type: 'done port: port]
365
365
unless res [res: awake make event! [type: 'ready port: port]]
366
366
]
@@ -370,7 +370,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
370
370
either spec/method = 'HEAD [
371
371
state/state: 'ready
372
372
res: awake make event! [type: 'custom port: port code: 0 ]
373
- ] [
373
+ ][
374
374
res: check-data port
375
375
unless open? port [
376
376
;NOTE some servers(e.g. yahoo.com) don't supply content-data in the redirect header so the state/state can be left in 'reading-data after check-data call
@@ -382,7 +382,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
382
382
;?? headers
383
383
;?? state/state
384
384
385
- if all [not res state/state = 'ready] [
385
+ if all [not res state/state = 'ready][
386
386
either all [
387
387
any [
388
388
find [get head ] spec/method
@@ -392,9 +392,9 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
392
392
]
393
393
]
394
394
in headers 'Location
395
- ] [
395
+ ][
396
396
return awake make event! [type: 'custom port: port code: 300 ]
397
- ] [
397
+ ][
398
398
state/error: make-http-error "Redirect requires manual intervention"
399
399
res: awake make event! [type: 'error port: port]
400
400
]
@@ -403,7 +403,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
403
403
unauthorized client-error server-error proxy-auth [
404
404
either spec/method = 'HEAD [
405
405
state/state: 'ready
406
- ] [
406
+ ][
407
407
check-data port
408
408
]
409
409
]
@@ -456,7 +456,7 @@ http-response-headers: context [
456
456
Last-Modified: none
457
457
]
458
458
459
- do-redirect : func [ port [port! ] new-uri [url! string! file! ] /local spec state] [
459
+ do-redirect : func [ port [port! ] new-uri [url! string! file! ] /local spec state] [
460
460
spec: port/spec
461
461
state: port/state
462
462
@@ -506,7 +506,7 @@ do-redirect: func [port [port!] new-uri [url! string! file!] /local spec state]
506
506
open port
507
507
]
508
508
509
- check-data : func [ port /local headers res data out chunk-size mk1 mk2 trailer state conn] [
509
+ check-data : func [ port /local headers res data out chunk-size mk1 mk2 trailer state conn] [
510
510
state: port/state
511
511
headers: state/info/headers
512
512
conn: state/connection
@@ -525,32 +525,32 @@ check-data: func [port /local headers res data out chunk-size mk1 mk2 trailer st
525
525
either parse/all data [
526
526
copy chunk-size some hex-digits
527
527
crlfbin mk1: to end
528
- ] [
528
+ ][
529
529
chunk-size: to integer! to issue! to string! chunk-size
530
530
sys/log/more 'HTTP ["chunk-size:^[ [m" chunk-size]
531
531
either chunk-size = 0 [
532
532
if parse/all mk1 [
533
533
crlfbin (trailer: "" ) to end | copy trailer to crlf2bin to end
534
- ] [
534
+ ][
535
535
trailer: construct trailer
536
536
append headers body-of trailer
537
537
state/state: 'ready
538
538
res: state/awake make event! [type: 'custom port: port code: 0 ]
539
539
clear data
540
540
]
541
541
true
542
- ] [
542
+ ][
543
543
either parse/all mk1 [
544
544
chunk-size skip mk2: crlfbin to end
545
- ] [
545
+ ][
546
546
insert /part tail out mk1 mk2
547
547
remove/part data skip mk2 2
548
548
empty? data
549
- ] [
549
+ ][
550
550
true
551
551
]
552
552
]
553
- ] [
553
+ ][
554
554
true
555
555
]
556
556
]
@@ -565,7 +565,7 @@ check-data: func [port /local headers res data out chunk-size mk1 mk2 trailer st
565
565
state/state: 'ready
566
566
conn/data: make binary! 32000 ;@@ Oldes: why not just none?
567
567
res: state/awake make event! [type: 'custom port: port code: 0 ]
568
- ] [
568
+ ][
569
569
;Awake from the WAIT loop to prevent timeout when reading big data. --Richard
570
570
res: true
571
571
]
@@ -602,24 +602,24 @@ sys/make-scheme [
602
602
actor: [
603
603
read : func [
604
604
port [port! ]
605
- ] [
605
+ ] [
606
606
sys/log/debug 'HTTP "read"
607
607
either any-function? : port/awake [
608
608
unless open? port [cause-error 'Access 'not-open port/spec/ref ]
609
609
if port/state/state <> 'ready [http-error "Port not ready" ]
610
610
port/state/awake: : port/awake
611
611
do-request port
612
- ] [
612
+ ][
613
613
sync-op port []
614
614
]
615
615
]
616
616
write : func [
617
617
port [port! ]
618
618
value
619
- ] [
619
+ ] [
620
620
sys/log/debug 'HTTP "write"
621
621
;?? port
622
- unless any [block? :value binary? :value any-string? :value ] [value: form :value ]
622
+ unless any [block? :value binary? :value any-string? :value ][value: form :value ]
623
623
unless block? value [value: reduce [[Content-Type: "application/x-www-form-urlencoded; charset=utf-8" ] value]]
624
624
625
625
either any-function? : port/awake [
@@ -628,14 +628,14 @@ sys/make-scheme [
628
628
port/state/awake: : port/awake
629
629
parse-write-dialect port value
630
630
do-request port
631
- ] [
631
+ ][
632
632
sync-op port [parse-write-dialect port value]
633
633
]
634
634
]
635
635
open : func [
636
636
port [port! ]
637
637
/local conn
638
- ] [
638
+ ] [
639
639
sys/log/debug 'HTTP ["open, state:" port/state ]
640
640
if port/state [return port]
641
641
if none? port/spec/host [http-error "Missing host address" ]
@@ -666,12 +666,12 @@ sys/make-scheme [
666
666
]
667
667
open? : func [
668
668
port [port! ]
669
- ] [
669
+ ] [
670
670
found? all [port/state open? port/state/connection ]
671
671
]
672
672
close : func [
673
673
port [port! ]
674
- ] [
674
+ ] [
675
675
sys/log/debug 'HTTP "close"
676
676
if port/state [
677
677
close port/state/connection
@@ -682,10 +682,10 @@ sys/make-scheme [
682
682
]
683
683
copy : func [
684
684
port [port! ]
685
- ] [
686
- either all [port/spec/method = 'HEAD port/state ] [
685
+ ] [
686
+ either all [port/spec/method = 'HEAD port/state ][
687
687
reduce bind [name size date] port/state/info
688
- ] [
688
+ ][
689
689
if port/data [copy port/data ]
690
690
]
691
691
]
@@ -694,8 +694,8 @@ sys/make-scheme [
694
694
/mode
695
695
field [word! block! none! ]
696
696
/local error state result
697
- ] [
698
- if all [mode none? field] [ return words-of system/schemes/http/info ]
697
+ ] [
698
+ if all [mode none? field][ return words-of system/schemes/http/info ]
699
699
if none? state: port/state [
700
700
open port ;there is port opening in sync-op, but it would also close the port later and so clear the state
701
701
attempt [sync-op port [parse-write-dialect port [HEAD ]]]
@@ -725,8 +725,8 @@ sys/make-scheme [
725
725
]
726
726
length? : func [
727
727
port [port! ]
728
- ] [
729
- either port/data [length? port/data ] [0 ]
728
+ ] [
729
+ either port/data [length? port/data ][0 ]
730
730
]
731
731
]
732
732
User-Agent: none
0 commit comments