1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Shared response utilities for HTTP relay endpoints.
//!
//! # Response Patterns
//!
//! Handlers should use these patterns consistently:
//!
//! - **`build_response()`**: Use when forwarding stored messages that may have
//! a Content-Type header (e.g., GET /inbox/{id}, GET /link/{id}).
//!
//! - **`(StatusCode, Bytes)`**: Use for simple responses without Content-Type
//! (e.g., POST success, DELETE success/failure, errors, ACK status).
//!
//! This keeps simple cases simple while providing Content-Type forwarding
//! only where needed.
use ;
/// Maximum allowed length for IDs (in bytes).
/// 256 bytes accommodates typical ID patterns (UUIDs are 36 chars, base64-encoded
/// 256-bit keys are 44 chars) while preventing DoS via oversized HashMap keys.
pub const MAX_ID_LENGTH: usize = 256;
/// Validate that an ID doesn't exceed the maximum length.
/// Returns `Err` with a BAD_REQUEST response if the ID is too long.
/// Build a response with optional Content-Type header.
///
/// Use this for message bodies that may have a stored Content-Type.
/// For simple responses (errors, ACKs), prefer `(StatusCode, Bytes)` tuples.