diff --git a/var/mongoose/cgi-bin/opkg.jim b/var/mongoose/cgi-bin/opkg.jim index 0fe5a7d9..366581bf 100755 --- a/var/mongoose/cgi-bin/opkg.jim +++ b/var/mongoose/cgi-bin/opkg.jim @@ -4,19 +4,18 @@ package require cgi source /mod/var/mongoose/lib/setup require pkg.class chunked -puts "Content-Type: text/html" -puts "Transfer-Encoding: chunked" -puts "" - cgi_input #cgi_dump set cmd [cgi_get cmd update] +start_chunked + set bcmd "|/mod/var/mongoose/lib/opkg $cmd" set fd [open $bcmd r] while {[gets $fd line] >= 0} { chunk "$line\r\n" + #chunk_pad } close $fd @@ -26,6 +25,5 @@ if {$cmd eq "update"} { chunk "Done.\r\n" } -chunk "" -puts "\r\n" +end_chunked diff --git a/var/mongoose/lib/chunked b/var/mongoose/lib/chunked index b439018b..5ff53920 100755 --- a/var/mongoose/lib/chunked +++ b/var/mongoose/lib/chunked @@ -5,6 +5,17 @@ proc chunk {chk} { flush stdout } -# Kick the browser into life... -chunk [string range [format "%301d" 0] 1 end-1] +proc chunk_pad {{len 256}} { + incr len + chunk [string range [format "%${len}d" 0] 1 end-1] +} + +proc start_chunked {{type "text/html"}} { + puts -nonewline "Content-Type: $type\r\n" + puts -nonewline "Transfer-Encoding: chunked\r\n\r\n" +} + +proc end_chunked {} { + puts -nonewline "0\r\n\r\n\r\n" +}