︙ | | |
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
-
+
-
+
|
}
if {$len>0} {
# Still need to read the query content
dict set W .toread $len
} else {
# There is no query content, so handle the request immediately
set wapp $W
wappInt-handle-request $chan 0
wappInt-handle-request $chan
}
}
} else {
# If .toread is set, that means we are reading the query content.
# Continue reading until .toread reaches zero.
set got [read $chan [dict get $W .toread]]
dict append W CONTENT $got
dict set W .toread [expr {[dict get $W .toread]-[string length $got]}]
if {[dict get $W .toread]<=0} {
# Handle the request as soon as all the query content is received
set wapp $W
wappInt-handle-request $chan 0
wappInt-handle-request $chan
}
}
}
# Decode the HTTP request header.
#
# This routine is always running inside of a [catch], so if
|
︙ | | |
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
-
+
-
+
-
+
-
+
|
# instance finishes. Yes, this means that WAPP IS SINGLE THREADED. Only
# a single page rendering instance my be running at a time. There can
# be multiple HTTP requests inbound at once, but only one my be processed
# at a time once the request is full read and parsed.
#
set wappIntPending {}
set wappIntLock 0
proc wappInt-handle-request {chan useCgi} {
proc wappInt-handle-request {chan} {
global wappIntPending wappIntLock
fileevent $chan readable {}
if {$wappIntLock} {
# Another instance of request is already running, so defer this one
lappend wappIntPending [list wappInt-handle-request $chan $useCgi]
lappend wappIntPending [list wappInt-handle-request $chan]
return
}
set wappIntLock 1
catch [list wappInt-handle-request-unsafe $chan $useCgi]
catch [list wappInt-handle-request-unsafe $chan]
set wappIntLock 0
if {[llength $wappIntPending]>0} {
# If there are deferred requests, then launch the oldest one
after idle [lindex $wappIntPending 0]
set wappIntPending [lrange $wappIntPending 1 end]
}
}
proc wappInt-handle-request-unsafe {chan useCgi} {
proc wappInt-handle-request-unsafe {chan} {
global wapp
dict set wapp .reply {}
dict set wapp .mimetype {text/html; charset=utf-8}
dict set wapp .reply-code {200 Ok}
dict set wapp .csp {default-src 'self'}
# Set up additional CGI environment values
|
︙ | | |
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
-
+
|
}
if {$len>0} {
fconfigure stdin -translation binary
dict set wapp CONTENT [read stdin $len]
}
dict set wapp WAPP_MODE cgi
fconfigure stdout -translation binary
wappInt-handle-request stdout 1
wappInt-handle-request-unsafe stdout
}
# Process new text received on an inbound SCGI request
#
proc wappInt-scgi-readable {chan} {
if {[catch [list wappInt-scgi-readable-unsafe $chan] msg]} {
puts stderr "$msg\n$::errorInfo"
|
︙ | | |
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
|
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
|
-
+
-
+
|
if {$len>0} {
# Still need to read the query content
dict set W .toread $len
} else {
# There is no query content, so handle the request immediately
dict set W SERVER_ADDR [dict get $W .remove_addr]
set wapp $W
wappInt-handle-request $chan 0
wappInt-handle-request $chan
}
} else {
# If .toread is set, that means we are reading the query content.
# Continue reading until .toread reaches zero.
set got [read $chan [dict get $W .toread]]
dict append W CONTENT $got
dict set W .toread [expr {[dict get $W .toread]-[string length $got]}]
if {[dict get $W .toread]<=0} {
# Handle the request as soon as all the query content is received
dict set W SERVER_ADDR [dict get $W .remove_addr]
set wapp $W
wappInt-handle-request $chan 0
wappInt-handle-request $chan
}
}
}
# Start up the wapp framework. Parameters are a list passed as the
# single argument.
#
|
︙ | | |