dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36505?usp=email ) Change subject: HTTP_Adapter: allow body to be "omit" ...................................................................... HTTP_Adapter: allow body to be "omit" In HTTP not all requests have a body. At the moment we describe a missing body with body := "". This is not 100% correct since the rest of the code interprets this as a present body with zero length and will put a content_length = 0 header line into the HTTP header, even in the GET request. This will most likely be ignored by any HTTP server, but it is still not 100% spec compliant. Related: SYS#6824 Change-Id: Ifedc8c2a590835663d1ba0b08b1fe4d54bdd0fff --- M library/HTTP_Adapter.ttcn 1 file changed, 38 insertions(+), 11 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/05/36505/1 diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn index 879313d..968b44f 100644 --- a/library/HTTP_Adapter.ttcn +++ b/library/HTTP_Adapter.ttcn @@ -73,21 +73,31 @@ return hdr; } -template (value) HTTPMessage ts_HTTP_Req(charstring url, - charstring method := "GET", - charstring body := "", - integer v_maj := 1, integer v_min := 1, - charstring host, - HeaderLines custom_hdr := { }) := { - request := { +function ts_HTTP_Req(charstring url, + charstring method := "GET", + template charstring body := omit, + integer v_maj := 1, integer v_min := 1, + charstring host, + HeaderLines custom_hdr := { }) +return template (value) HTTPMessage { + var HTTPMessage msg; + + msg.request := { client_id := omit, method := method, uri := url, version_major := v_maj, version_minor := v_min, - header := valueof(ts_HTTP_Header(body, host, custom_hdr)), - body := body + header := valueof(ts_HTTP_Header(body, host, custom_hdr)) } + + if (ispresent(body)) { + msg.request.body := valueof(body); + } else { + msg.request.body := ""; + } + + return msg; } template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := { @@ -104,7 +114,7 @@ template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299)); -function f_http_tx_request(charstring url, charstring method := "GET", charstring body := "", +function f_http_tx_request(charstring url, charstring method := "GET", template charstring body := omit, HeaderLines custom_hdr := { }) runs on http_CT { HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port)); @@ -135,7 +145,7 @@ /* 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, + template charstring 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); -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36505?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: Ifedc8c2a590835663d1ba0b08b1fe4d54bdd0fff Gerrit-Change-Number: 36505 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier@sysmocom.de> Gerrit-MessageType: newchange