Problem
http-server response templates can access .request.url, .request.headers, .request.vars, and .req_num, but they cannot directly access the inbound request host (http.Request.Host).
This makes it difficult for mock APIs to emit realistic absolute pagination URLs, such as RFC 5988 Link headers, that preserve the same origin the client used for the request.
Using {{ hostname }} returns the container's OS hostname. In elastic-package system tests, Elastic Agent often connects through a network alias such as svc-github, while the container hostname may be a generated container ID unless explicitly configured. That mismatch can make mocks emit pagination links whose origin differs from the configured request URL.
Proposed enhancement
Expose the inbound request host in the template context, for example:
data := map[string]interface{}{
"req_num": count,
"request": map[string]interface{}{
"host": r.Host,
"vars": mux.Vars(r),
"url": r.URL,
"headers": r.Header,
},
}
Example usage
responses:
- status_code: 200
headers:
Link:
- '<http://{{ .request.host }}/orgs/test/audit-log?after=abcd>; rel="next"'
body: |
[]
This lets fixtures generate same-origin absolute URLs from the actual request instead of hardcoding a Docker network alias or relying on the container hostname.
Note
request.URL.Hostname() is not sufficient for this use case because server-side Go HTTP requests usually have a relative URL. The host is stored in http.Request.Host.
Problem
http-serverresponse templates can access.request.url,.request.headers,.request.vars, and.req_num, but they cannot directly access the inbound request host (http.Request.Host).This makes it difficult for mock APIs to emit realistic absolute pagination URLs, such as RFC 5988
Linkheaders, that preserve the same origin the client used for the request.Using
{{ hostname }}returns the container's OS hostname. In elastic-package system tests, Elastic Agent often connects through a network alias such assvc-github, while the container hostname may be a generated container ID unless explicitly configured. That mismatch can make mocks emit pagination links whose origin differs from the configured request URL.Proposed enhancement
Expose the inbound request host in the template context, for example:
Example usage
This lets fixtures generate same-origin absolute URLs from the actual request instead of hardcoding a Docker network alias or relying on the container hostname.
Note
request.URL.Hostname()is not sufficient for this use case because server-side Go HTTP requests usually have a relative URL. The host is stored inhttp.Request.Host.