Skip to main content

arminius_lib_nats/
headers.rs

1// SPDX-FileCopyrightText: 2025 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! Custom NATS message headers used by the request-reply transport.
6
7use async_nats::HeaderMap;
8
9/// Header carrying the subject a responder should publish its reply to.
10///
11/// Set by the requesting side
12/// ([`Requester::request`](arminius_lib_message_bus::Requester)) and read by
13/// the responding side. Keeping the reply address in a header —
14/// rather than in the serialized payload — lets the message bus carry only the
15/// domain payload in the body.
16pub const REPLY_SUBJECT_HEADER: &str = "X-Arminius-Reply-Subject";
17
18/// Records `subject` as the reply address on `headers`.
19pub fn set_reply_subject(headers: &mut HeaderMap, subject: &str) {
20	headers.insert(REPLY_SUBJECT_HEADER, subject);
21}
22
23/// Reads the reply subject from a message's headers, if present.
24pub fn reply_subject(headers: Option<&HeaderMap>) -> Option<String> {
25	headers?.get(REPLY_SUBJECT_HEADER).map(ToString::to_string)
26}
27
28#[cfg(test)]
29mod tests;