SR Technology WTK Repo
Check-in [4203b1f82a]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:remove some debugging output for cleaner log on console output
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4203b1f82a2fe49bc934a534a85c281691a80814
User & Date: stever 2013-01-16 22:02:47
Context
2013-01-17
13:41
disable bg polling loop after upgrading connectin to WebSockets check-in: 9da8d541a8 user: stever tags: trunk
2013-01-16
22:02
remove some debugging output for cleaner log on console output check-in: 4203b1f82a user: stever tags: trunk
21:53
tweak server reponse console output to differentiate websocket responses check-in: b167328223 user: stever tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/httpd.tcl.

817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
#       view            If specified as "1", don't return as attachment.
#       flag            If specified as "-static" emit ETag etc. headers.
# Results:
#       None.

proc HttpdReturnFile {sock file filename mimetype timestamp {view ""} {flag ""}} {
	global final$sock
puts "$file $filename"
    upvar #0 Httpd$sock data
    set version "1"; if {[info exists data(version)] && $data(version)!=""} {set version $data(version)}
    puts $sock "HTTP/1.$version 200 Data follows"
    puts $sock "Date: [HttpdDate [clock seconds]]"
    if {$view!="1"} {
        puts $sock "Content-Disposition: attachment; filename=\"$filename\""
    } else {






<







817
818
819
820
821
822
823

824
825
826
827
828
829
830
#       view            If specified as "1", don't return as attachment.
#       flag            If specified as "-static" emit ETag etc. headers.
# Results:
#       None.

proc HttpdReturnFile {sock file filename mimetype timestamp {view ""} {flag ""}} {
	global final$sock

    upvar #0 Httpd$sock data
    set version "1"; if {[info exists data(version)] && $data(version)!=""} {set version $data(version)}
    puts $sock "HTTP/1.$version 200 Data follows"
    puts $sock "Date: [HttpdDate [clock seconds]]"
    if {$view!="1"} {
        puts $sock "Content-Disposition: attachment; filename=\"$filename\""
    } else {

Changes to server.tcl.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
		puts "WSCLIENT: $cmd"; [dict get $::session($sessionid) interp] eval wtk::fromclient [list $cmd]
	}
}


proc ws_upgrade {sock data} {
	fileevent $sock readable {}
	puts "**ws $sock"
	foreach {key val} $data {
		puts "$key = $val"
	}
	
	if {[dict get $data mime,sec-websocket-version] == "13"} {
		puts "\nVersion 13 ok"
		set acceptKey  "[dict get $data mime,sec-websocket-key]258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
		set acceptKey  [binary encode base64 [sha1::sha1 -bin $acceptKey]]
		set upgrade    "HTTP/1.1 101 Switching Protocols\r\n"
		append upgrade "Upgrade: websocket\r\n"
		append upgrade "Connection: Upgrade\r\n"
		append upgrade "WebSocket-Origin: http://[dict get $data mime,host]\r\n"
		append upgrade	"WebSocket-Location: ws://localhost:9001/wsctrl\r\n"
		append upgrade "Sec-WebSocket-Accept: $acceptKey"
		append upgrade "\r\n\r\n"
		puts -nonewline $upgrade
		fconfigure $sock -translation binary
		puts -nonewline $sock $upgrade
		flush $sock
		#after 1000
		fileevent $sock readable [list ws_receive junk $sock]
		puts "Socket $sock upgraded to WebSocket"
		set sessionid [lindex [split [dict get $data query] =] end]
		dict set ::session($sessionid) wsock $sock
		dict set ::sock($sock) sessionid $sessionid
		ws_send $sock "Hello From Server"
		return 1
	} else {
		puts "\nVersion != 13 no good"
		close $sock
		return 0
	}
}

# webhandler -- Respond to HTTP requests we receive
#






<
<
<
|
<

|









<



<








|







67
68
69
70
71
72
73



74

75
76
77
78
79
80
81
82
83
84
85

86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
		puts "WSCLIENT: $cmd"; [dict get $::session($sessionid) interp] eval wtk::fromclient [list $cmd]
	}
}


proc ws_upgrade {sock data} {
	fileevent $sock readable {}





	if {[dict get $data mime,sec-websocket-version] == "13"} {
		#puts "\nVersion 13 ok"
		set acceptKey  "[dict get $data mime,sec-websocket-key]258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
		set acceptKey  [binary encode base64 [sha1::sha1 -bin $acceptKey]]
		set upgrade    "HTTP/1.1 101 Switching Protocols\r\n"
		append upgrade "Upgrade: websocket\r\n"
		append upgrade "Connection: Upgrade\r\n"
		append upgrade "WebSocket-Origin: http://[dict get $data mime,host]\r\n"
		append upgrade	"WebSocket-Location: ws://localhost:9001/wsctrl\r\n"
		append upgrade "Sec-WebSocket-Accept: $acceptKey"
		append upgrade "\r\n\r\n"

		fconfigure $sock -translation binary
		puts -nonewline $sock $upgrade
		flush $sock

		fileevent $sock readable [list ws_receive junk $sock]
		puts "Socket $sock upgraded to WebSocket"
		set sessionid [lindex [split [dict get $data query] =] end]
		dict set ::session($sessionid) wsock $sock
		dict set ::sock($sock) sessionid $sessionid
		ws_send $sock "Hello From Server"
		return 1
	} else {
		#puts "\nVersion != 13 no good"
		close $sock
		return 0
	}
}

# webhandler -- Respond to HTTP requests we receive
#