Skip to content

Commit 15cb76a

Browse files
committed
FIX: small code cleanup
1 parent cdd10e7 commit 15cb76a

File tree

2 files changed

+80
-80
lines changed

2 files changed

+80
-80
lines changed

src/mezz/prot-http.r

+49-49
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ REBOL [
3131
]
3232
]
3333

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][
3535
unless port/state [open port port/state/close?: yes]
3636
state: port/state
3737
state/awake: :read-sync-awake
@@ -41,7 +41,7 @@ sync-op: func [port body /local state encoding content-type code-page tmp] [
4141
;The timeout should be triggered only when the response from other side exceeds the timeout value.
4242
;--Richard
4343
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][
4545
state/error: make-http-error "HTTP(s) Timeout"
4646
break
4747
]
@@ -104,7 +104,7 @@ sync-op: func [port body /local state encoding content-type code-page tmp] [
104104
]
105105
body
106106
]
107-
read-sync-awake: func [event [event!] /local error] [
107+
read-sync-awake: func [event [event!] /local error][
108108
sys/log/debug 'HTTP ["read-sync-awake:" event/type]
109109
switch/default event/type [
110110
connect ready [
@@ -118,7 +118,7 @@ read-sync-awake: func [event [event!] /local error] [
118118
true
119119
]
120120
custom [
121-
if all [event/offset event/offset/x = 300] [
121+
if all [event/offset event/offset/x = 300][
122122
event/port/state/state: 'redirect
123123
return true
124124
]
@@ -133,11 +133,11 @@ read-sync-awake: func [event [event!] /local error] [
133133
]
134134
if error? error [do error]
135135
]
136-
] [
136+
][
137137
false
138138
]
139139
]
140-
http-awake: func [event /local port http-port state awake res] [
140+
http-awake: func [event /local port http-port state awake res][
141141
port: event/port
142142
http-port: port/locals
143143
state: http-port/state
@@ -174,10 +174,10 @@ http-awake: func [event /local port http-port state awake res] [
174174
awake make event! [type: 'error port: http-port]
175175
]
176176
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"][
178178
state/error: make-http-error "Server closed connection"
179179
awake make event! [type: 'error port: http-port]
180-
] [
180+
][
181181
;set state to CLOSE so the WAIT loop in 'sync-op can be interrupted --Richard
182182
state/state: 'close
183183
any [
@@ -192,12 +192,12 @@ http-awake: func [event /local port http-port state awake res] [
192192
if error? state/error [ do state/error ]
193193
res
194194
]
195-
] [true]
195+
][true]
196196
]
197197
make-http-error: func [
198198
"Make an error for the HTTP protocol"
199199
message [string! block!]
200-
] [
200+
][
201201
if block? message [message: ajoin message]
202202
make error! [
203203
type: 'Access
@@ -213,10 +213,10 @@ make-http-request: func [
213213
headers [block!] "Request headers (set-word! string! pairs)"
214214
content [any-string! binary! none!] {Request contents (Content-Length is created automatically). Empty string not exactly like none.}
215215
/local result
216-
] [
216+
][
217217
result: rejoin [
218218
uppercase form method #" "
219-
either file? target [next mold target] [target]
219+
either file? target [next mold target][target]
220220
" HTTP/1.1" CRLF
221221
]
222222
foreach [word string] headers [
@@ -237,7 +237,7 @@ do-request: func [
237237
"Perform an HTTP request"
238238
port [port!]
239239
/local spec info
240-
] [
240+
][
241241
spec: port/spec
242242
info: port/state/info
243243
spec/headers: body-of make make object! [
@@ -246,7 +246,7 @@ do-request: func [
246246
Accept-Encoding: "gzip,deflate"
247247
Host: either not find [80 443] spec/port-id [
248248
rejoin [form spec/host #":" spec/port-id]
249-
] [
249+
][
250250
form spec/host
251251
]
252252
User-Agent: any [system/schemes/http/User-Agent "REBOL"]
@@ -259,13 +259,13 @@ do-request: func [
259259

260260
write port/state/connection make-http-request spec/method enhex any [spec/path %/] spec/headers spec/content
261261
]
262-
parse-write-dialect: func [port block /local spec] [
262+
parse-write-dialect: func [port block /local spec][
263263
spec: port/spec
264264
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)]
266266
]
267267
]
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][
269269
state: port/state
270270
conn: state/connection
271271
info: state/info
@@ -288,7 +288,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
288288
sys/log/debug 'HTML "server using malformed line separator of #{0A0A}"
289289
]
290290
]
291-
] [
291+
][
292292
info/response-line: line: to string! copy/part conn/data d1
293293
sys/log/more 'HTTP line
294294
;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
356356
state/state: 'ready
357357
res: awake make event! [type: 'done port: port]
358358
unless res [res: awake make event! [type: 'ready port: port]]
359-
] [
359+
][
360360
res: check-data port
361361
;?? res
362362
;?? state/state
363-
if all [not res state/state = 'ready] [
363+
if all [not res state/state = 'ready][
364364
res: awake make event! [type: 'done port: port]
365365
unless res [res: awake make event! [type: 'ready port: port]]
366366
]
@@ -370,7 +370,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
370370
either spec/method = 'HEAD [
371371
state/state: 'ready
372372
res: awake make event! [type: 'custom port: port code: 0]
373-
] [
373+
][
374374
res: check-data port
375375
unless open? port [
376376
;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
382382
;?? headers
383383
;?? state/state
384384

385-
if all [not res state/state = 'ready] [
385+
if all [not res state/state = 'ready][
386386
either all [
387387
any [
388388
find [get head] spec/method
@@ -392,9 +392,9 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
392392
]
393393
]
394394
in headers 'Location
395-
] [
395+
][
396396
return awake make event! [type: 'custom port: port code: 300]
397-
] [
397+
][
398398
state/error: make-http-error "Redirect requires manual intervention"
399399
res: awake make event! [type: 'error port: port]
400400
]
@@ -403,7 +403,7 @@ check-response: func [port /local conn res headers d1 d2 line info state awake s
403403
unauthorized client-error server-error proxy-auth [
404404
either spec/method = 'HEAD [
405405
state/state: 'ready
406-
] [
406+
][
407407
check-data port
408408
]
409409
]
@@ -456,7 +456,7 @@ http-response-headers: context [
456456
Last-Modified: none
457457
]
458458

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][
460460
spec: port/spec
461461
state: port/state
462462

@@ -506,7 +506,7 @@ do-redirect: func [port [port!] new-uri [url! string! file!] /local spec state]
506506
open port
507507
]
508508

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][
510510
state: port/state
511511
headers: state/info/headers
512512
conn: state/connection
@@ -525,32 +525,32 @@ check-data: func [port /local headers res data out chunk-size mk1 mk2 trailer st
525525
either parse/all data [
526526
copy chunk-size some hex-digits
527527
crlfbin mk1: to end
528-
] [
528+
][
529529
chunk-size: to integer! to issue! to string! chunk-size
530530
sys/log/more 'HTTP ["chunk-size:^[[m" chunk-size]
531531
either chunk-size = 0 [
532532
if parse/all mk1 [
533533
crlfbin (trailer: "") to end | copy trailer to crlf2bin to end
534-
] [
534+
][
535535
trailer: construct trailer
536536
append headers body-of trailer
537537
state/state: 'ready
538538
res: state/awake make event! [type: 'custom port: port code: 0]
539539
clear data
540540
]
541541
true
542-
] [
542+
][
543543
either parse/all mk1 [
544544
chunk-size skip mk2: crlfbin to end
545-
] [
545+
][
546546
insert/part tail out mk1 mk2
547547
remove/part data skip mk2 2
548548
empty? data
549-
] [
549+
][
550550
true
551551
]
552552
]
553-
] [
553+
][
554554
true
555555
]
556556
]
@@ -565,7 +565,7 @@ check-data: func [port /local headers res data out chunk-size mk1 mk2 trailer st
565565
state/state: 'ready
566566
conn/data: make binary! 32000 ;@@ Oldes: why not just none?
567567
res: state/awake make event! [type: 'custom port: port code: 0]
568-
] [
568+
][
569569
;Awake from the WAIT loop to prevent timeout when reading big data. --Richard
570570
res: true
571571
]
@@ -602,24 +602,24 @@ sys/make-scheme [
602602
actor: [
603603
read: func [
604604
port [port!]
605-
] [
605+
][
606606
sys/log/debug 'HTTP "read"
607607
either any-function? :port/awake [
608608
unless open? port [cause-error 'Access 'not-open port/spec/ref]
609609
if port/state/state <> 'ready [http-error "Port not ready"]
610610
port/state/awake: :port/awake
611611
do-request port
612-
] [
612+
][
613613
sync-op port []
614614
]
615615
]
616616
write: func [
617617
port [port!]
618618
value
619-
] [
619+
][
620620
sys/log/debug 'HTTP "write"
621621
;?? 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]
623623
unless block? value [value: reduce [[Content-Type: "application/x-www-form-urlencoded; charset=utf-8"] value]]
624624

625625
either any-function? :port/awake [
@@ -628,14 +628,14 @@ sys/make-scheme [
628628
port/state/awake: :port/awake
629629
parse-write-dialect port value
630630
do-request port
631-
] [
631+
][
632632
sync-op port [parse-write-dialect port value]
633633
]
634634
]
635635
open: func [
636636
port [port!]
637637
/local conn
638-
] [
638+
][
639639
sys/log/debug 'HTTP ["open, state:" port/state]
640640
if port/state [return port]
641641
if none? port/spec/host [http-error "Missing host address"]
@@ -666,12 +666,12 @@ sys/make-scheme [
666666
]
667667
open?: func [
668668
port [port!]
669-
] [
669+
][
670670
found? all [port/state open? port/state/connection]
671671
]
672672
close: func [
673673
port [port!]
674-
] [
674+
][
675675
sys/log/debug 'HTTP "close"
676676
if port/state [
677677
close port/state/connection
@@ -682,10 +682,10 @@ sys/make-scheme [
682682
]
683683
copy: func [
684684
port [port!]
685-
] [
686-
either all [port/spec/method = 'HEAD port/state] [
685+
][
686+
either all [port/spec/method = 'HEAD port/state][
687687
reduce bind [name size date] port/state/info
688-
] [
688+
][
689689
if port/data [copy port/data]
690690
]
691691
]
@@ -694,8 +694,8 @@ sys/make-scheme [
694694
/mode
695695
field [word! block! none!]
696696
/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]
699699
if none? state: port/state [
700700
open port ;there is port opening in sync-op, but it would also close the port later and so clear the state
701701
attempt [sync-op port [parse-write-dialect port [HEAD]]]
@@ -725,8 +725,8 @@ sys/make-scheme [
725725
]
726726
length?: func [
727727
port [port!]
728-
] [
729-
either port/data [length? port/data] [0]
728+
][
729+
either port/data [length? port/data][0]
730730
]
731731
]
732732
User-Agent: none

0 commit comments

Comments
 (0)