Hi Ian,
there are at least two problem areas. The first one is the DNS lookup-up:
- the standard DNS-lookup in NaviServer does not support timeouts.
one approach is to use the nsdns module [1], where one can perform the
lookup via
ns_dns resolve hostname ?-type type? ?-server server?
?-timeout timeout?
and bypass the lookup in ns_http by providing it a resolved IP address.
However, as you pointed out, this is just a part of the equation.
If one connects to a host via HTTP, the timeout works as expected,
but the timeout via HTTPS leads to a long blocking request, when nobody
listens at the backend.
The situation with SSL is more complex, because the connect() operation
via OpenSSL (and friends) is more than just a unix connect(), since it
requires a handshake (read and write operations), where several
things can go wrong, etc..... but fixing this should bo big hassle.
i will look into this in the near future
all the best
-g
[1] https://bitbucket.org/naviserver/nsdns/src/default/
On 04.05.18 01:15, Ian Harding wrote:
I am trying to use ns_http with an https uri and finding that the
-timeout seems not to work if the host does not exist. I get
ssl connect failed: error:00000000:lib(0):func(0):reason(0)
When I run it with a short timeout against an existing server I see:
seattle-vm-1-0:nscp 1> catch [http_post https://someserver.com ""
[list Content-type text/html" GET]] err
ns_http failed: timeout
When I run it with a short timeout against a server with a DNS entry
but no actual listener I see the ssl connect failed error.
Is there any way for the timeout to include the ssl handshake?
Here's my proc fyi:
proc http_post {hostname post_data {headerlist {Content-type
application/x-www-form-urlencoded}} {method POST}} {
# Simple script to stop using curl
# arguments are
# hostname: URI to connect to
# post_data: url encoded post data stuck together with
ampersands like a GET
# headers: optional list of header names and value (Optional
defaults to post header)
# method: POST or GET. LOL bad proc name (Optional defaults to
POST)
# returns
# the data returned
set queryHeaders [ns_set create]
set replyHeaders [ns_set create]
foreach {key value} $headerlist {
ns_set put $queryHeaders $key $value
}
set h [ns_http queue -method $method -timeout 1:0 -headers
$queryHeaders -body $post_data $hostname]
ns_http wait -elapsed E -timeout 1:0 -result returnval
-headers $replyHeaders -status S $h
ns_log notice "[lindex [info level 0] 0] status code: $S
elapsed: $E"
ns_log notice "[lindex [info level 0] 0]reply: $returnval"
return $returnval
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel