laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36645?usp=email )
Change subject: HTTP_Adapter: add support for binary messages
......................................................................
HTTP_Adapter: add support for binary messages
The HTTP_Adapter currently only supports text only HTTP messages. However,
the HTTPmsg testport API also has a way to deal with binary HTTP messages.
Related: SYS#6824
Change-Id: I18340f19ed462bf80af683dc9f2831b602f4bdf7
---
M library/HTTP_Adapter.ttcn
1 file changed, 76 insertions(+), 5 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
pespin: Looks good to me, but someone else must approve
diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn
index d26cce5..c78c40a 100644
--- a/library/HTTP_Adapter.ttcn
+++ b/library/HTTP_Adapter.ttcn
@@ -71,11 +71,17 @@
}
function f_ts_HTTP_Header(template (omit) charstring body := omit,
+ template (omit) octetstring binary_body := omit,
template (omit) charstring host := omit,
HeaderLines custom_hdr := { })
return template (value) HeaderLines {
var HeaderLines hdr := { };
+ /* Make sure we never use body or binary_body at the same time */
+ if (not istemplatekind(body, "omit") and not istemplatekind(binary_body,
"omit")) {
+ setverdict(fail, "use wither (ascii) body or binary_body");
+ }
+
/* Build default header */
if (not istemplatekind(host, "omit")) {
hdr := hdr & {valueof(ts_HeaderLine("Host", valueof(host)))};
@@ -84,6 +90,9 @@
if (not istemplatekind(body, "omit")) {
hdr := hdr & {valueof(ts_HeaderLine("Content-Length",
int2str(lengthof(body))))};
}
+ else if (not istemplatekind(binary_body, "omit")) {
+ hdr := hdr & {valueof(ts_HeaderLine("Content-Length",
int2str(lengthof(binary_body))))};
+ }
return f_overlay_HTTP_Header(hdr, custom_hdr);
}
@@ -107,11 +116,36 @@
uri := url,
version_major := v_maj,
version_minor := v_min,
- header := f_ts_HTTP_Header(body, host, custom_hdr),
+ header := f_ts_HTTP_Header(body, omit, host, custom_hdr),
body := f_ts_body_or_empty(body)
}
}
+function f_ts_body_or_empty_bin(template (omit) octetstring body) return template (value)
octetstring {
+ if (istemplatekind(body, "omit")) {
+ return ''O;
+ }
+ return body;
+}
+
+template (value) HTTPMessage ts_HTTP_Req_Bin(charstring url,
+ charstring method := "GET",
+ template (omit) octetstring body := omit,
+ integer v_maj := 1, integer v_min := 1,
+ charstring host,
+ HeaderLines custom_hdr := { }) := {
+ request_binary := {
+ client_id := omit,
+ method := method,
+ uri := url,
+ version_major := v_maj,
+ version_minor := v_min,
+ header := f_ts_HTTP_Header(omit, body, host, custom_hdr),
+ body := f_ts_body_or_empty_bin(body)
+ }
+}
+
+
template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := {
response := {
client_id := ?,
@@ -124,14 +158,33 @@
}
};
+template HTTPMessage tr_HTTP_Resp_Bin(template integer sts := ?) := {
+ response_binary := {
+ client_id := ?,
+ version_major := ?,
+ version_minor := ?,
+ statuscode := sts,
+ statustext := ?,
+ header := ?,
+ body := ?
+ }
+};
+
template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299));
-function f_http_tx_request(charstring url, charstring method := "GET", template
charstring body := omit,
+function f_http_tx_request(charstring url, charstring method := "GET",
+ template charstring body := omit,
+ template octetstring binary_body := omit,
HeaderLines custom_hdr := { })
runs on http_CT {
HTTP.send(ts_HTTP_Connect(g_pars.http_host, g_pars.http_port, g_pars.use_ssl));
HTTP.receive(Connect_result:?);
- HTTP.send(ts_HTTP_Req(url, method, body, host := g_pars.http_host & ":"
& int2str(g_pars.http_port), custom_hdr := custom_hdr));
+
+ if (not istemplatekind(body, "omit")) {
+ HTTP.send(ts_HTTP_Req(url, method, body, host := g_pars.http_host & ":"
& int2str(g_pars.http_port), custom_hdr := custom_hdr));
+ } else if (not istemplatekind(binary_body, "omit")) {
+ HTTP.send(ts_HTTP_Req_Bin(url, method, binary_body, host := g_pars.http_host &
":" & int2str(g_pars.http_port), custom_hdr := custom_hdr));
+ }
}
function f_http_rx_response(template HTTPMessage exp := tr_HTTP_Resp2xx, float tout :=
2.0)
@@ -146,6 +199,9 @@
[] HTTP.receive(tr_HTTP_Resp) -> value resp {
setverdict(fail, "Unexpected HTTP response ", resp);
}
+ [] HTTP.receive(tr_HTTP_Resp_Bin) -> value resp {
+ setverdict(fail, "Unexpected (binary) HTTP response ", resp);
+ }
[] T.timeout {
setverdict(fail, "Timeout waiting for HTTP response");
self.stop;
@@ -157,10 +213,12 @@
/* run a HTTP request and return the response */
function f_http_transact(charstring url, charstring method := "GET",
- template (omit) charstring body := omit, template HTTPMessage exp :=
tr_HTTP_Resp2xx,
+ template (omit) charstring body := omit,
+ template (omit) octetstring binary_body := omit,
+ template HTTPMessage exp := tr_HTTP_Resp2xx,
float tout := 2.0, HeaderLines custom_hdr := { })
runs on http_CT return HTTPMessage {
- f_http_tx_request(url, method, body, custom_hdr);
+ f_http_tx_request(url, method, body, binary_body, custom_hdr);
return f_http_rx_response(exp, tout);
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36645?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I18340f19ed462bf80af683dc9f2831b602f4bdf7
Gerrit-Change-Number: 36645
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged