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
This commit is contained in:
Philipp Maier 2024-03-26 15:50:22 +01:00
parent 6406e6d9db
commit ef20fa083b
1 changed files with 12 additions and 5 deletions

View File

@ -84,9 +84,16 @@ return template (value) HeaderLines {
return f_overlay_HTTP_Header(hdr, custom_hdr);
}
function f_ts_body_or_empty(template (omit) charstring body) return template (value) charstring {
if (istemplatekind(body, "omit")) {
return "";
}
return body;
}
template (value) HTTPMessage ts_HTTP_Req(charstring url,
charstring method := "GET",
charstring body := "",
template (omit) charstring body := omit,
integer v_maj := 1, integer v_min := 1,
charstring host,
HeaderLines custom_hdr := { }) := {
@ -96,8 +103,8 @@ template (value) HTTPMessage ts_HTTP_Req(charstring url,
uri := url,
version_major := v_maj,
version_minor := v_min,
header := valueof(f_ts_HTTP_Header(body, host, custom_hdr)),
body := body
header := f_ts_HTTP_Header(body, host, custom_hdr),
body := f_ts_body_or_empty(body)
}
}
@ -115,7 +122,7 @@ template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := {
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));
@ -146,7 +153,7 @@ runs on http_CT return HTTPMessage {
/* 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 (omit) 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);