
# Test of the new http_client API module
# 
# (C) 2016 Edvina AB, Sollentuna, Sweden. All rights reserved.
#
#

debug=2
log_stderror=yes
fork=no

# ------------------ module loading ----------------------------------
# Set a path to known locations for modules
#
mpath="/usr/local/lib64/kamailio/modules:/usr/local/lib/kamailio/modules:/usr/lib64/kamailio/modules:/usr/lib/kamailio/modules"
loadmodule "pv.so"	# For pseudo-variable support in log messages etc
loadmodule "xlog.so"	# For extended logging with pseudovariables
loadmodule "kex.so" 	# Kamailio extensions: 
			# Script flags and basic mi commands (version, pwd, get_statistics)
#
#
loadmodule "sl.so" 	# Stateless replies - needed by registrar.so
loadmodule "rtimer.so" 	# For ticks
loadmodule "htable.so" 	# For init event route
loadmodule "cfgutils.so" 	# Memory debugging

loadmodule "http_client.so" 	# The HTTP client module
loadmodule "httpapitest.so" 	# The HTTP client API test module -using the API to http_client.so

# main routing logic

modparam("http_client", "connection_timeout", 42);
modparam("http_client", "keep_connections", 1);
modparam("http_client", "maxdatasize", 1000);
modparam("http_client", "useragent", "Olle's Peace and Restful little HTTP grabber 42.3");
#user and password
modparam("http_client", "httpcon", "lisa=>https://www.kamailio.org/w/");


# -------------------------  request routing logic -------------------
route {
	sl_send_reply(400, "Do not wake me up");
	exit;
}

onreply_route {
	xlog("L_INFO", "<-- Incoming response: $rs $rr - from $si\n");
}

onsend_route
{
	xlog("ONSEND --> Sending from $sndfrom(proto):$sndfrom(ip):$sndfrom(port) to $sndto(proto):$sndto(ip):$sndto(port) \n");
}

# This route is executed at Kamailio start
event_route[htable:mod-init]
{
	xlog("L_ERR", "### Kamailio starting $timef(%HH:%mm) \n");
	$var(html) = "";

	$var(res) = test_http_connect("lisa", "", "$avp(html)");

	xlog("L_ERR", "-- Lisa http_client connection: Result $var(res) Response:\n--------\n$avp(html)\n------\n");


}

