MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / pack_header

Function pack_header

src/environmentd/src/http/webhook.rs:256–292  ·  view source on GitHub ↗

Pack the headers of a request into a [`Row`].

(
    mut body_row: BodyRow,
    headers: &BTreeMap<String, String>,
    header_tys: &WebhookHeaders,
)

Source from the content-addressed store, hash-verified

254
255/// Pack the headers of a request into a [`Row`].
256fn pack_header(
257 mut body_row: BodyRow,
258 headers: &BTreeMap<String, String>,
259 header_tys: &WebhookHeaders,
260) -> Result<Row, AppendWebhookError> {
261 // 1 column for the body plus however many are needed for the headers.
262 let num_cols = 1 + header_tys.num_columns();
263 // The provided Row already has the Body written.
264 let mut num_cols_written = 1;
265
266 let mut packer = RowPacker::for_existing_row(body_row.inner_mut());
267
268 // Pack the headers into our row, if required.
269 if let Some(filters) = &header_tys.header_column {
270 packer.push_dict(
271 filter_headers(headers, filters).map(|(name, val)| (name, Datum::String(val))),
272 );
273 num_cols_written += 1;
274 }
275
276 // Pack the mapped headers.
277 for idx in num_cols_written..num_cols {
278 let (header_name, use_bytes) = header_tys
279 .mapped_headers
280 .get(&idx)
281 .ok_or_else(|| anyhow::anyhow!("Invalid header column index {idx}"))?;
282 let header = headers.get(header_name);
283 let datum = match header {
284 Some(h) if *use_bytes => Datum::Bytes(h.as_bytes()),
285 Some(h) => Datum::String(h),
286 None => Datum::Null,
287 };
288 packer.push(datum);
289 }
290
291 Ok(body_row.into_inner())
292}
293
294fn filter_headers<'a: 'b, 'b>(
295 headers: &'a BTreeMap<String, String>,

Callers 1

pack_rowsFunction · 0.85

Calls 10

filter_headersFunction · 0.85
StringClass · 0.85
num_columnsMethod · 0.80
push_dictMethod · 0.80
inner_mutMethod · 0.45
mapMethod · 0.45
getMethod · 0.45
as_bytesMethod · 0.45
pushMethod · 0.45
into_innerMethod · 0.45

Tested by

no test coverage detected