[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..

HTTP_Adapter: allow API users to specifiy custom header

At the moment HTTP_Adapter can only make requests with a fixed
pre-defined HTTP header. However, some application may require
additional custom header lines or different values than the ones
specified in the pre-defined HTTP header.

Related: SYS#6824
Change-Id: I115fd14254e0957c0955649aeb47059dc180bf57
---
M library/HTTP_Adapter.ttcn
1 file changed, 68 insertions(+), 10 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved




diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn
index 0885f05..b302a80 100644
--- a/library/HTTP_Adapter.ttcn
+++ b/library/HTTP_Adapter.ttcn
@@ -15,6 +15,7 @@

 import from HTTPmsg_Types all;
 import from HTTPmsg_PortType all;
+import from Native_Functions all;

 type component http_CT {
port HTTPmsg_PT HTTP;
@@ -37,24 +38,65 @@
 }
 template (value) Close ts_HTTP_Close := { client_id := omit };

-template (value) HeaderLines ts_HTTP_Header(charstring body, charstring host) 
:= {
-   { header_name := "Host", header_value := host },
-   { header_name := "Content-Type", header_value := "application/json" },
-   { header_name := "Content-Length", header_value := 
int2str(lengthof(body)) }
+/* function to add HeaderLines to a an existing set of HeaderLines. 
HeaderLines that are already present, are updated. */
+function f_overlay_HTTP_Header(HeaderLines hdr, HeaderLines additional_hdr) 
return template (value) HeaderLines
+{
+   var integer i;
+   var integer k;
+   var boolean updated;
+
+   for (i := 0; i < lengthof(additional_hdr); i := i+1) {
+   updated := false;
+   for (k := 0; k < lengthof(hdr); k := k+1) {
+   if (f_str_tolower(hdr[k].header_name) == 
f_str_tolower(additional_hdr[i].header_name)) {
+   hdr[k] := additional_hdr[i];
+   updated := true;
+   }
+   }
+   if (updated == false) {
+   hdr := hdr & { additional_hdr[i] };
+   }
+   }
+
+   return hdr;
+}
+
+template (value) HeaderLine ts_HeaderLine(charstring header_name, charstring 
header_value) := {
+   header_name := header_name,
+   header_value := header_value
+}
+
+function f_ts_HTTP_Header(template (omit) charstring body := omit,
+ template (omit) charstring host := omit,
+ HeaderLines custom_hdr := { })
+return template (value) HeaderLines {
+   var HeaderLines hdr := { };
+
+   /* Build default header */
+   if (not istemplatekind(host, "omit")) {
+   hdr := hdr & {valueof(ts_HeaderLine("Host", valueof(host)))};
+   }
+   hdr := hdr & {{ header_name := "Content-Type", header_value := 
"application/json" }};
+   if (not istemplatekind(body, "omit")) {
+   hdr := hdr & {valueof(ts_HeaderLine("Content-Length", 
int2str(lengthof(body};
+   }
+
+   return f_overlay_HTTP_Header(hdr, custom_hdr);
 }

 template (value) HTTPMessage ts_HTTP_Req(charstring url,
 charstring method := "GET",
 charstring body := "",
 integer v_maj := 1, integer v_min := 1,
-charstring host) := {
+charstring host,
+HeaderLines custom_hdr := { }) := {
request := {
client_id := omit,
method := method,
uri := url,
version_major := v_maj,
version_minor := v_min,
-   header := valueof(ts_HTTP_Header(body, host)),
+   header := valueof(f_ts_HTTP_Header(body, host, custom_hdr)),
body := body
}
 }
@@ -73,11 +115,12 @@

 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", 
charstring body := "",
+  HeaderLines custom_hdr := { })
 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, host := g_http_host & ":" & 
int2str(g_http_port)));
+   HTTP.send(ts_HTTP_Req(url, method, body, host := g_http_host & ":" & 
int2str(g_http_port), custom_hdr := custom_hdr));
 }

 function f_http_rx_response(template HTTPMessage exp := 

[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread laforge
Attention is currently required from: dexter.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 5: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 5
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Wed, 24 Apr 2024 17:18:37 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread laforge
Attention is currently required from: dexter.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 5: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 5
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Wed, 24 Apr 2024 17:18:35 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread pespin
Attention is currently required from: dexter, laforge.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 5: Code-Review+1

(2 comments)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/464528a9_6fe17a53
PS3, Line 73:   var HeaderLines hdr := { };
> I am not sure if that really works. […]
I see, no need to spend more time if it doesn't work out, was worth a try 
though.


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/5bc53de6_98c7b6a3
PS3, Line 77:   hdr := hdr & {valueof(ts_HeaderLine("Host", 
valueof(host)))};
> (see above, I removed the valueof as suggested)
Done



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 5
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Wed, 24 Apr 2024 14:09:46 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: pespin 
Comment-In-Reply-To: dexter 
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread dexter
Attention is currently required from: laforge, pespin.

dexter has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 5:

(3 comments)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/ca8eb4c0_68f6f6dc
PS3, Line 73:   var HeaderLines hdr := { };
> You can turn this into a "var template (value) Headerlines hdr := {};"
I am not sure if that really works. I have tried that out, but I get an error: 
"error: Reference to a value was expected instead of template variable `hdr'" 
(line 77, where the concatenation happens) maybe the concatenation needs a 
value rather than a template?


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/bbfd7a33_0e1d38c5
PS3, Line 77:   hdr := hdr & {valueof(ts_HeaderLine("Host", 
valueof(host)))};
> ...so you don't need to do valueof() each time.
(see above, I removed the valueof as suggested)


File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/89986111_5fc1bb22
PS4, Line 57:h
> indent issue (tab missing)
Done



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 5
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Wed, 24 Apr 2024 10:53:48 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: laforge 
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-24 Thread dexter
Attention is currently required from: laforge, pespin.

Hello Jenkins Builder, laforge, pespin,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email

to look at the new patch set (#5).

The following approvals got outdated and were removed:
Code-Review+1 by laforge, Code-Review+1 by pespin, Verified+1 by Jenkins Builder


Change subject: HTTP_Adapter: allow API users to specifiy custom header
..

HTTP_Adapter: allow API users to specifiy custom header

At the moment HTTP_Adapter can only make requests with a fixed
pre-defined HTTP header. However, some application may require
additional custom header lines or different values than the ones
specified in the pre-defined HTTP header.

Related: SYS#6824
Change-Id: I115fd14254e0957c0955649aeb47059dc180bf57
---
M library/HTTP_Adapter.ttcn
1 file changed, 68 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/04/36504/5
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 5
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: pespin 
Gerrit-MessageType: newpatchset


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-23 Thread laforge
Attention is currently required from: dexter.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 4: Code-Review+1

(1 comment)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/5527cc0d_740e5850
PS4, Line 57:h
indent issue (tab missing)



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Tue, 23 Apr 2024 12:19:23 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-22 Thread pespin
Attention is currently required from: dexter.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 3: Code-Review+1

(3 comments)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/f40c2f29_ea003c39
PS3, Line 73:   var HeaderLines hdr := { };
You can turn this into a "var template (value) Headerlines hdr := {};"


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/80373014_71280887
PS3, Line 77:   hdr := hdr & {valueof(ts_HeaderLine("Host", 
valueof(host)))};
...so you don't need to do valueof() each time.


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/5c68e4df_b21f5cd1
PS3, Line 84:   return f_overlay_HTTP_Header(hdr, custom_hdr);
then f_overlay_HTTP_Header could receive a "template (value)", or do valueof() 
once here.



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 3
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Mon, 22 Apr 2024 09:23:30 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-22 Thread dexter
Attention is currently required from: pespin.

dexter has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 3:

(1 comment)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/e0dfdaf4_aeb63212
PS2, Line 72:   hdr := hdr & {{ header_name := "Host", header_value := 
valueof(host) }};
> hint: I usually find it way more readable to use templates instead of filling 
> records, eg: […]
Done



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 3
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Mon, 22 Apr 2024 09:20:10 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-22 Thread dexter
Attention is currently required from: pespin.

Hello Jenkins Builder, pespin,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Code-Review+1 by pespin, Verified+1 by Jenkins Builder


Change subject: HTTP_Adapter: allow API users to specifiy custom header
..

HTTP_Adapter: allow API users to specifiy custom header

At the moment HTTP_Adapter can only make requests with a fixed
pre-defined HTTP header. However, some application may require
additional custom header lines or different values than the ones
specified in the pre-defined HTTP header.

Related: SYS#6824
Change-Id: I115fd14254e0957c0955649aeb47059dc180bf57
---
M library/HTTP_Adapter.ttcn
1 file changed, 68 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/04/36504/3
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 3
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: pespin 
Gerrit-MessageType: newpatchset


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-19 Thread pespin
Attention is currently required from: dexter.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 2: Code-Review+1

(1 comment)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/efa2dddb_8ad3cd12
PS2, Line 72:   hdr := hdr & {{ header_name := "Host", header_value := 
valueof(host) }};
hint: I usually find it way more readable to use templates instead of filling 
records, eg:
   hdr := hdr & { ts_Header("Host", host) };



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 2
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Fri, 19 Apr 2024 13:54:56 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-19 Thread dexter
Attention is currently required from: pespin.

Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder


Change subject: HTTP_Adapter: allow API users to specifiy custom header
..

HTTP_Adapter: allow API users to specifiy custom header

At the moment HTTP_Adapter can only make requests with a fixed
pre-defined HTTP header. However, some application may require
additional custom header lines or different values than the ones
specified in the pre-defined HTTP header.

Related: SYS#6824
Change-Id: I115fd14254e0957c0955649aeb47059dc180bf57
---
M library/HTTP_Adapter.ttcn
1 file changed, 63 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/04/36504/2
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 2
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: pespin 
Gerrit-Attention: pespin 
Gerrit-MessageType: newpatchset


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-19 Thread dexter
Attention is currently required from: pespin.

dexter has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 2:

(4 comments)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/a703254b_c50d7499
PS1, Line 41: function ts_HTTP_Header(template charstring body := omit,
> I'd prefer having this one prefixed "f_ts_", since it's actually a function. 
> […]
Done


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/c033169a_48c0c19c
PS1, Line 42:   template charstring host := omit,
> template (omit) charstring
Done


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/2752abad_bcf7364b
PS1, Line 55:   if (ispresent(body)) {
> I'm not sure ispresent() can be used this way, or only for optional fields in 
> a record. […]
I have verified that it works with ispresent(), but if (not 
istemplatekind(body, "omit")) also works.


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/05a2da73_5e253896
PS1, Line 59:   /* Add custom header lines, already existing headers (name) are 
updated */
> I think it makes sense to move this to a separate function "merge_headers()" 
> or "overlay_headers()". […]
Done



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 2
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: pespin 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Fri, 19 Apr 2024 11:55:40 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-02 Thread pespin
Attention is currently required from: dexter.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )

Change subject: HTTP_Adapter: allow API users to specifiy custom header
..


Patch Set 1:

(4 comments)

File library/HTTP_Adapter.ttcn:

https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/fa87a4c6_ed625695
PS1, Line 41: function ts_HTTP_Header(template charstring body := omit,
I'd prefer having this one prefixed "f_ts_", since it's actually a function.
Furthermore, this is a ts_ template, so it makes no sense to receive a 
"template charstring". It should be at least "template (omit) charstring".


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/c144563b_a13d3c6e
PS1, Line 42:   template charstring host := omit,
template (omit) charstring


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/79f1158b_02fef378
PS1, Line 55:   if (ispresent(body)) {
I'm not sure ispresent() can be used this way, or only for optional fields in a 
record. You probably need "istemplatekind". Make sure ispresent() doesn't 
return always true here.


https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504/comment/0d028e9e_752b2958
PS1, Line 59:   /* Add custom header lines, already existing headers (name) are 
updated */
I think it makes sense to move this to a separate function "merge_headers()" or 
"overlay_headers()".
This way the test can also simply get the regular header and call that function.



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?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: I115fd14254e0957c0955649aeb47059dc180bf57
Gerrit-Change-Number: 36504
Gerrit-PatchSet: 1
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: pespin 
Gerrit-Attention: dexter 
Gerrit-Comment-Date: Tue, 02 Apr 2024 15:35:51 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in osmo-ttcn3-hacks[master]: HTTP_Adapter: allow API users to specifiy custom header

2024-04-02 Thread dexter
dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36504?usp=email )


Change subject: HTTP_Adapter: allow API users to specifiy custom header
..

HTTP_Adapter: allow API users to specifiy custom header

At the moment HTTP_Adapter can only make requests with a fixed
pre-defined HTTP header. However, some application may require
additional custom header lines or different values than the ones
specified in the pre-defined HTTP header.

Related: SYS#6824
Change-Id: I115fd14254e0957c0955649aeb47059dc180bf57
---
M library/HTTP_Adapter.ttcn
1 file changed, 57 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/04/36504/1

diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn
index 0885f05..879313d 100644
--- a/library/HTTP_Adapter.ttcn
+++ b/library/HTTP_Adapter.ttcn
@@ -15,6 +15,7 @@

 import from HTTPmsg_Types all;
 import from HTTPmsg_PortType all;
+import from Native_Functions all;

 type component http_CT {
port HTTPmsg_PT HTTP;
@@ -37,24 +38,54 @@
 }
 template (value) Close ts_HTTP_Close := { client_id := omit };

-template (value) HeaderLines ts_HTTP_Header(charstring body, charstring host) 
:= {
-   { header_name := "Host", header_value := host },
-   { header_name := "Content-Type", header_value := "application/json" },
-   { header_name := "Content-Length", header_value := 
int2str(lengthof(body)) }
+function ts_HTTP_Header(template charstring body := omit,
+   template charstring host := omit,
+   HeaderLines custom_hdr := { })
+return template (value) HeaderLines {
+   var HeaderLines hdr := { };
+   var integer i;
+   var integer k;
+   var boolean updated;
+
+   /* Build default header */
+   if (ispresent(host)) {
+   hdr := hdr & {{ header_name := "Host", header_value := 
valueof(host) }};
+   }
+   hdr := hdr & {{ header_name := "Content-Type", header_value := 
"application/json" }};
+   if (ispresent(body)) {
+   hdr := hdr & {{ header_name := "Content-Length", header_value 
:= int2str(lengthof(body)) }}
+   }
+
+   /* Add custom header lines, already existing headers (name) are updated 
*/
+   for (i := 0; i < lengthof(custom_hdr); i := i+1) {
+   updated := false;
+   for (k := 0; k < lengthof(hdr); k := k+1) {
+   if (f_str_tolower(hdr[k].header_name) == 
f_str_tolower(custom_hdr[i].header_name)) {
+   hdr[k] := custom_hdr[i];
+   updated := true;
+   }
+   }
+   if (updated == false) {
+  hdr := hdr & { custom_hdr[i] };
+   }
+   }
+
+   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) := {
+charstring host,
+HeaderLines custom_hdr := { }) := {
request := {
client_id := omit,
method := method,
uri := url,
version_major := v_maj,
version_minor := v_min,
-   header := valueof(ts_HTTP_Header(body, host)),
+   header := valueof(ts_HTTP_Header(body, host, custom_hdr)),
body := body
}
 }
@@ -73,11 +104,12 @@

 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", 
charstring body := "",
+  HeaderLines custom_hdr := { })
 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, host := g_http_host & ":" & 
int2str(g_http_port)));
+   HTTP.send(ts_HTTP_Req(url, method, body, host := g_http_host & ":" & 
int2str(g_http_port), custom_hdr := custom_hdr));
 }

 function f_http_rx_response(template HTTPMessage exp := tr_HTTP_Resp2xx, float 
tout := 2.0)
@@ -104,9 +136,9 @@
 /* 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)
+float tout := 2.0, HeaderLines custom_hdr := { })
 runs on http_CT return HTTPMessage {
-   f_http_tx_request(url, method, body);
+