HTTP_Adapter: split into f_http_tx_request() / f_http_rx_response()

There are some use cases in which we don't want a blocking wait for the
full HTTP request to complete.  Let's split it up in two parts, and
make the existing f_http_transact() a wrapper around them.

Also, enable the generation of the Connect_result primitive to detect
connection failures.

Change-Id: I5c7575c0b58c3606d25d8f8cfccd47cfb7a8c400
This commit is contained in:
Harald Welte 2021-02-22 09:16:21 +01:00 committed by laforge
parent ad9d8366f8
commit 205b537f6f
2 changed files with 18 additions and 9 deletions

View File

@ -71,17 +71,17 @@ template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := {
template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299));
/* run a HTTP request and return the response */
function f_http_transact(charstring url, charstring method := "GET",
charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx,
float tout := 2.0)
function f_http_tx_request(charstring url, charstring method := "GET", charstring body := "")
runs on http_CT {
HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port));
HTTP.receive(Connect_result:?);
HTTP.send(ts_HTTP_Req(url, method, body));
}
function f_http_rx_response(template HTTPMessage exp := tr_HTTP_Resp2xx, float tout := 2.0)
runs on http_CT return HTTPMessage {
var HTTPMessage resp;
timer T := tout;
HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port));
//HTTP.receive(Connect_result:?);
HTTP.send(ts_HTTP_Req(url, method, body));
T.start;
alt {
[] HTTP.receive(exp) -> value resp {
@ -99,4 +99,13 @@ runs on http_CT return HTTPMessage {
return resp;
}
/* run a HTTP request and return the response */
function f_http_transact(charstring url, charstring method := "GET",
charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx,
float tout := 2.0)
runs on http_CT return HTTPMessage {
f_http_tx_request(url, method, body);
return f_http_rx_response(exp, tout);
}
}

View File

@ -1,3 +1,3 @@
[TESTPORT_PARAMETERS]
system.HTTP.http_debugging := "yes"
system.HTTP.use_notification_ASPs := "no"
system.HTTP.use_notification_ASPs := "yes"