-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsgi.tcl
74 lines (57 loc) · 2 KB
/
wsgi.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#------------------------------------------------------------#
# Client/Framework #
#------------------------------------------------------------#
proc application {environ reponse} {
set status "200 OK"
dict set headers "Content-Type" "text/plain"
$response $status $headers
return "Hello World!"
}
#------------------------------------------------------------#
# Server/Gateway #
#------------------------------------------------------------#
namespace eval wsgi {
proc run {application} {
set environ [array get ::env]
dict set environ "wsgi.input" stdin
dict set environ "wsgi.erros" stderr
dict set environ "wsgi.version" [list 1 0]
dict set environ "wsgi.multithread" 0
dict set environ "wsgi.multiprocess" 1
dict set environ "wsgi.run_once" 1
dict set environ "wsgi.url_scheme" "http"
dict set environ REQUEST_METHOD ""
dict set environ SCRIPT_NAME ""
dict set environ PATH_INFO ""
dict set environ QUERY_STRING ""
dict set environ CONTENT_TYPE ""
dict set environ CONTENT_LENGTH ""
dict set environ SERVER_NAME ""
dict set environ SERVER_PORT ""
dict set environ SERVER_PROTOCOL "HTTP/1.1"
dict set environ HTTP_* ""
set result [$application $environ [namespace current]::response]
foreach data $result {
write $data
}
}
proc send_header {status headers} {
puts "Status: $status"
dict for {name value} $headers {
puts "$name: $value"
}
puts ""
fconfigure stdout -encoding binary -translation binary
}
proc write {data} {
puts -nonewline $data
flush
}
proc response {status headers} {
send_header $status $headers
}
}
#------------------------------------------------------------#
# Middleware #
#------------------------------------------------------------#
TODO