dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39657?usp=email )
Change subject: HTTP_Adapter: allow requests to different hosts
......................................................................
HTTP_Adapter: allow requests to different hosts
The host that is requested via the HTTP_Adapter is configured once on
initialization. This is fine if the test scenario only has exactly one
destination to query. For multiple destinations, this model does not
work. Let's add an http_pars parameter to the request functions, so
that the user can direct the requests to different hosts dynamically.
Related: SYS#7339
Change-Id: Ic87674f2381b3c6a1be6d0ce28a9e5403cda201b
---
M library/HTTP_Adapter.ttcn
1 file changed, 27 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/57/39657/1
diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn
index d970416..d9f4a82 100644
--- a/library/HTTP_Adapter.ttcn
+++ b/library/HTTP_Adapter.ttcn
@@ -20,7 +20,7 @@
type component http_CT {
port HTTPmsg_PT HTTP;
/* double underscore to have "g_pars" available on components extending this
one: */
- var HTTP_Adapter_Params g_http_pars;
+ var template HTTP_Adapter_Params g_http_pars;
};
type record HTTP_Adapter_Params {
@@ -29,9 +29,9 @@
boolean use_ssl
};
-function f_http_init(HTTP_Adapter_Params pars) runs on http_CT {
+function f_http_init(template HTTP_Adapter_Params http_pars := omit) runs on http_CT {
map(self:HTTP, system:HTTP);
- g_http_pars := pars;
+ g_http_pars := http_pars;
}
template (value) Connect ts_HTTP_Connect(template (value) charstring hostname,
@@ -180,15 +180,31 @@
template octetstring binary_body := omit,
HeaderLines custom_hdr := { },
float tout := 2.0,
- template integer client_id := omit)
+ template integer client_id := omit,
+ template HTTP_Adapter_Params http_pars := omit)
runs on http_CT {
var Connect_result rc;
timer T := tout;
var template integer use_client_id := omit;
+ var HTTP_Adapter_Params use_http_pars;
+
+ if (istemplatekind(http_pars, "omit")) {
+ if (istemplatekind(g_http_pars, "omit")) {
+ /* The user is expected to either pass global http_pars with on initialization
(f_http_init) or
+ * to pass individual http_pars with each request. */
+ setverdict(fail, "no HTTP parameters set");
+ self.stop;
+ }
+ /* Use globally set HTTP parameters */
+ use_http_pars := valueof(g_http_pars);
+ } else {
+ /* Use request-individual HTTP parameters */
+ use_http_pars := valueof(http_pars);
+ }
/* In case the caller didn't specify a client_id, we will create a new connection.
*/
if (istemplatekind(client_id, "omit")) {
- HTTP.send(ts_HTTP_Connect(g_http_pars.http_host, g_http_pars.http_port,
g_http_pars.use_ssl));
+ HTTP.send(ts_HTTP_Connect(use_http_pars.http_host, use_http_pars.http_port,
use_http_pars.use_ssl));
T.start;
alt {
[] HTTP.receive(Connect_result:?) -> value rc;
@@ -208,16 +224,16 @@
if (not istemplatekind(body, "omit") and istemplatekind(binary_body,
"omit")) {
/* HTTP message with ASCII content */
- HTTP.send(ts_HTTP_Req(url, method, body, host := g_http_pars.http_host &
":" & int2str(g_http_pars.http_port),
+ HTTP.send(ts_HTTP_Req(url, method, body, host := use_http_pars.http_host &
":" & int2str(use_http_pars.http_port),
custom_hdr := custom_hdr, client_id := use_client_id));
} else if (not istemplatekind(binary_body, "omit") and istemplatekind(body,
"omit")) {
/* HTTP message with binary content */
HTTP.send(ts_HTTP_Req_Bin(url, method, binary_body,
- host := g_http_pars.http_host & ":" &
int2str(g_http_pars.http_port),
+ host := use_http_pars.http_host & ":" &
int2str(use_http_pars.http_port),
custom_hdr := custom_hdr, client_id := use_client_id));
} else if (istemplatekind(binary_body, "omit") and istemplatekind(body,
"omit")) {
/* HTTP message without content (e.g. a GET request) */
- HTTP.send(ts_HTTP_Req(url, method, host := g_http_pars.http_host & ":"
& int2str(g_http_pars.http_port),
+ HTTP.send(ts_HTTP_Req(url, method, host := use_http_pars.http_host & ":"
& int2str(use_http_pars.http_port),
custom_hdr := custom_hdr, client_id := use_client_id));
} else {
setverdict(fail, "either binary_body or body must be used (a request can contain
either ASCII data or binary data, not both!");
@@ -262,9 +278,10 @@
template HTTPMessage exp := tr_HTTP_Resp2xx,
float tout := 2.0, HeaderLines custom_hdr := { },
template integer client_id := omit,
- boolean keep_connection := false)
+ boolean keep_connection := false,
+ template HTTP_Adapter_Params http_pars := omit)
runs on http_CT return HTTPMessage {
- f_http_tx_request(url, method, body, binary_body, custom_hdr, tout, client_id);
+ f_http_tx_request(url, method, body, binary_body, custom_hdr, tout, client_id,
http_pars);
return f_http_rx_response(exp, tout, client_id, keep_connection);
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39657?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ic87674f2381b3c6a1be6d0ce28a9e5403cda201b
Gerrit-Change-Number: 39657
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>