-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscgi.tcl
38 lines (26 loc) · 858 Bytes
/
scgi.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/path/to/scgi.tm
proc scgi::respond {sock header body} {
if {[dict exist $header SCRIPT_FILENAME]} {
set script_file [dict get $header SCRIPT_FILENAME]
set interp [interp create]
dict for {key value} $header {
array set ::env [list $key $value]
}
$interp alias puts scgi::print $sock
$interp alias header scgi::println $sock
$interp eval source $script_file
dict for {key value} $header {
array unset ::env $key
}
interp delete $interp
return
}
scgi::println $sock "HTTP/1.1 200 OK"
#scgi::println $sock "Status: 200 OK"
#scgi::println $sock "Date: Wed, 09 Sep 2015 07:13:51 GMT"
scgi::println $sock "Content-Type: text/plain"
scgi::println $sock "Connection: close"
scgi::println $sock ""
scgi::println $sock $header
scgi::println $sock "hello [clock seconds]"
}