On 10/18/2017 11:18 AM, Alexey Noskov wrote:
Dear All,

Recently, I have encountered with two troubles.

1)))


Because of some reason it quite difficult to configure Apache Rivet to use UTF-8 properly.

It responded a web pages in ISO8859-1 instead of UTF-8.


I've just finished a couple of pure UTF-8 web sites and it wasn't that hard.


The following Apache configuration DO NOT (surprisingly to me) make rivet to respond a proper UTF-8 pages

(because of headers configuration browser detects it as UTF-8, but text itself is

encoded in ISO8859-1):

/AddDefaultCharset UTF-8/

/AddType application/x-httpd-rivet .rvt
AddType application/x-rivet-tcl .tcl
AddType 'application/x-httpd-rivet;charset=utf-8' rvt
AddType 'application/x-rivet-tcl;charset=utf-8' tcl/


Remove the first two AddType definitions. Just

AddType 'application/x-httpd-rivet;charset=utf-8' rvt
AddType 'application/x-rivet-tcl;charset=utf-8' tcl

AddDefaultCharset is a weapon to be used with care because it affects other web sites hosted on the same Apache instance. For debugging add also the directive

RivetServerConf HonorHeaderOnlyRequests On

and see what happens if you read the headers sent. My project responds in this way

% package require http
2.8.9
% set tk [::http::geturl "http://yourwebsite/";]
::http::1
% dict get [::http::meta $tk] Content-Type
text/html; charset=utf-8

HTML files contain the metatag:

/<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>/

JSON files contain the header:

/::rivet::headers type "application/json; charset=UTF-8"/


In think this is correct if you're sending JSON messages but if you can get the encoding straight for the whole website you can probably avoid it

The problem is solved by adding the following
lines of Tcl code info initscript of Rivet:

/encoding system utf-8
fconfigure stdin -encoding utf-8
fconfigure stdout -encoding utf-8/

Thus by default stdin and stdout are configured to use ISO8859-1.


I think the configuration could binary with translation=none. You don't want the channel to do anything on your data, you want it to get through to the client in a pristine state. Am I wrong?

I use latest (last update was about month ago) dev version of Rivet and
apache from debian jessie repository. Probably there is no such issue for
the latest version of apache or for others OS-s (e.g.,I heard that in CentOS
Apache is configured to use UTF-8 by default in contrast to debian).

2)))


I have a question.

How is it possible to set a timeout for a .tcl Rivet page???

I have an api, I would
like to reject requests taking more than 3 seconds for processing
(SQL for some requests sometimes need quite long time, I am trying to just reject such
requests during the execution)

I've tried standard Apache's Timeout and KeepAliveTimeout directives - no effect - for a .tcl scripts.
Additionally I tried to utilize Tcl's after command in the following way:

/ after 3000 {puts rejected;::rivet::exit}/


Don't use ::rivet::exit whenever possible. This script should work (it works to me with rivet 2.3, I haven't checked with 3.0)

puts "timed wait..."
flush stdout

#while {1} { after 10 }

after 1000 { puts "OK"; incr wvariable}

vwait wvariable

Any ideas?


An interesting question. So the example above shows it's certainly possible if you can pursue a strict non-blocking design of your code. If you have a Tcl script stuck on, say, a socket or sucked into an infinite loop (just to make a pure conceptual example) I'm afraid you can't do much except for killing the script execution. Rivet should be responding correctly to asynchronous events (something that once upon a time it did not and it was the cause of some grievances from Harald) and this can be exploited to check with some timer event.

Years ago I showed that also the Tcl thread package can be exploited. You could start a 'time out thread' at the very beginning of critical section and let your code check regularly with the timeout thread to see if some sort of signal is raised.

 -- Massimo


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscr...@tcl.apache.org
For additional commands, e-mail: rivet-dev-h...@tcl.apache.org

Reply via email to