diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2024-03-25 15:08:43 +0100 |
---|---|---|
committer | dexter <pmaier@sysmocom.de> | 2024-04-18 12:06:45 +0000 |
commit | 4a19b474a940a2409eb2add0de039f7492f28367 (patch) | |
tree | 5e9f0972def0c200850069d67b62c5afcd5d988c | |
parent | 3d815762631f19c68df91b29bb071cccbd6a49ce (diff) |
HTTP_Adapter: add HOST field to header lines.
In HTTP 1.1 (this is what the HTTP_Adapter uses), the Host header field
is mandatory, see also: RFC 2616, section 14.23.
Related: SYS#6824
Change-Id: Id4b2220da4b2b5fbe74cdc2776cf66d6b34ddbcf
-rw-r--r-- | library/HTTP_Adapter.ttcn | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn index a957fdd9..0885f058 100644 --- a/library/HTTP_Adapter.ttcn +++ b/library/HTTP_Adapter.ttcn @@ -37,7 +37,8 @@ template (value) Connect ts_HTTP_Connect(template (value) charstring hostname, } template (value) Close ts_HTTP_Close := { client_id := omit }; -template (value) HeaderLines ts_HTTP_Header(charstring body) := { +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)) } } @@ -45,14 +46,15 @@ template (value) HeaderLines ts_HTTP_Header(charstring body) := { template (value) HTTPMessage ts_HTTP_Req(charstring url, charstring method := "GET", charstring body := "", - integer v_maj := 1, integer v_min := 1) := { + integer v_maj := 1, integer v_min := 1, + charstring host) := { request := { client_id := omit, method := method, uri := url, version_major := v_maj, version_minor := v_min, - header := ts_HTTP_Header(body), + header := valueof(ts_HTTP_Header(body, host)), body := body } } @@ -75,7 +77,7 @@ function f_http_tx_request(charstring url, charstring method := "GET", charstrin 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)); + HTTP.send(ts_HTTP_Req(url, method, body, host := g_http_host & ":" & int2str(g_http_port))); } function f_http_rx_response(template HTTPMessage exp := tr_HTTP_Resp2xx, float tout := 2.0) |