@@ -547,41 +547,47 @@ sys/make-scheme [
547
547
out/content: none
548
548
]
549
549
550
- if error? err: try [
550
+ try /except [
551
551
write port buffer
552
552
][
553
553
;@@TODO: handle it without `print`; using on-error?
554
- print "Write failed!"
555
- probe copy/part buffer 100
554
+ print "** Write failed!"
555
+ ; probe copy/part buffer 100
556
556
Awake-Client make event! [type: 'close port: port ]
557
557
]
558
558
]
559
559
560
560
Do-log : function [ ctx] [
561
- msg: ajoin [
562
- ctx/remote-ip
563
- { - - [} to-CLF-idate now {] "}
564
- ctx/inp/method #" "
565
- to string! ctx/inp/target/original
566
- " HTTP/" ctx/inp/version {" }
567
- ctx/out/status #" "
568
- any [ctx/out/header/Content-Length #"-" ]
569
- #"^/"
570
- ]
571
- prin msg
572
- if file? ctx/config/log-access [
573
- try [write /append ctx/config/log-access msg]
574
- ]
575
- if all [
576
- ctx/out/status >= 400
577
- file? ctx/config/log-errors
561
+ try /except [
562
+ msg: ajoin [
563
+ ctx/remote-ip
564
+ { - - [} to-CLF-idate now {] "}
565
+ ctx/inp/method #" "
566
+ to string! ctx/inp/target/original
567
+ " HTTP/" ctx/inp/version {" }
568
+ ctx/out/status #" "
569
+ any [ctx/out/header/Content-Length #"-" ]
570
+ #"^/"
571
+ ]
572
+ prin msg
573
+ if file? ctx/config/log-access [
574
+ write /append ctx/config/log-access msg
575
+ ]
576
+ if all [
577
+ ctx/out/status >= 400
578
+ file? ctx/config/log-errors
579
+ ][
580
+ write /append ctx/config/log-errors msg
581
+ ]
578
582
][
579
- try [write /append ctx/config/log-errors msg]
583
+ print "** Failed to write a log"
584
+ print system/state/last-error
580
585
]
581
586
]
582
587
583
588
Awake-Client: wrap [
584
- from-method: ["GET" | "POST" | "HEAD" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | "OPTIONS" ]
589
+ chars-method: #[bitset! #{ 00000000000000007FFFFFE0 } ] ; #"A" - #"Z"
590
+ ;from-method: ["GET" | "POST" | "HEAD" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | "OPTIONS"]
585
591
chars: complement union space: charset " " charset [#"^@" - #"^_" ]
586
592
CRLF2BIN: #{ 0D0A0D0A }
587
593
@@ -601,12 +607,12 @@ sys/make-scheme [
601
607
READ [
602
608
sys/log/more 'HTTPD ["bytes:^[ [1m" length? port/data ]
603
609
either header-end: find/tail port/data CRLF2BIN [
604
- if error? err: try [
610
+ try /except [
605
611
if none? ctx/state [
606
612
with inp [
607
613
parse copy/part port/data header-end [
608
- copy method from -method some space
609
- copy target some chars some space
614
+ copy method some chars -method some space
615
+ copy target some chars some space
610
616
"HTTP/" copy version some chars thru CRLF
611
617
copy header to end
612
618
(
@@ -630,7 +636,7 @@ sys/make-scheme [
630
636
]
631
637
actor/on-read port/locals
632
638
][
633
- print err
639
+ print system /state/last-error
634
640
ctx/state: 'error
635
641
ctx/out/status: 500 ; Internal Server Error
636
642
]
@@ -659,10 +665,10 @@ sys/make-scheme [
659
665
close out/content ; closing source port
660
666
End-Client port
661
667
][
662
- if error? err: try [
668
+ try /except [
663
669
write port buffer
664
670
][
665
- print "Write failed (2)!"
671
+ print "** Write failed (2)!"
666
672
;probe buffer
667
673
End-Client port
668
674
]
@@ -740,9 +746,9 @@ sys/make-scheme [
740
746
append port/locals/clients client
741
747
742
748
sys/log/info 'HTTPD ["New client:^[ [1;31m" client/locals/remote ]
743
- if error? err: try [read client][
744
- print ["Failed to read new client:" client/locals/remote ]
745
- print err
749
+ try /except [read client][
750
+ print ["** Failed to read new client:" client/locals/remote ]
751
+ print system /state/last-error
746
752
]
747
753
]
748
754
0 commit comments