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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// Context attribute key storing the validated [`ParsedMultipart`] form payload.
pub const ATTR_PARSED_MULTIPART: &str = "hyperlane_plugin_multipart.form";
/// Default maximum total multipart request body bytes (`10 MiB`).
pub const DEFAULT_MAX_TOTAL_BYTES: usize = 10 * 1024 * 1024;
/// Default maximum total parts allowed in a single multipart request (`64`).
pub const DEFAULT_MAX_PARTS: usize = 64;
/// Default maximum uploaded files allowed in a single multipart request (`16`).
pub const DEFAULT_MAX_FILES: usize = 16;
/// Default maximum bytes allowed for a single uploaded file (`5 MiB`).
pub const DEFAULT_MAX_FILE_BYTES: usize = 5 * 1024 * 1024;
/// Default maximum bytes allowed for a single non-file form field (`64 KiB`).
pub const DEFAULT_MAX_FIELD_BYTES: usize = 64 * 1024;
/// Media type prefix identifying multipart form-data requests.
pub const MULTIPART_FORM_DATA_PREFIX: &str = "multipart/form-data";
/// Default `Content-Type` emitted for multipart error responses.
pub const DEFAULT_ERROR_CONTENT_TYPE: &str = "application/json; charset=utf-8";
/// Default `400 Bad Request` JSON body for malformed multipart payloads.
pub const DEFAULT_BAD_MULTIPART_BODY: & =
br#"{"error":"invalid_multipart","message":"malformed multipart/form-data payload"}"#;
/// Default `413 Payload Too Large` JSON body for oversized uploads or part limits.
pub const DEFAULT_TOO_LARGE_BODY: & =
br#"{"error":"payload_too_large","message":"multipart upload exceeds configured limits"}"#;
/// Default `415 Unsupported Media Type` JSON body for disallowed uploaded file MIME types.
pub const DEFAULT_DISALLOWED_MIME_BODY: & =
br#"{"error":"unsupported_media_type","message":"uploaded file media type is not allowed"}"#;
/// Default fallback filename when sanitization strips all characters.
pub const FALLBACK_FILENAME: &str = "upload";
/// Boundary parameter prefix (`boundary=`).
pub const BOUNDARY_PARAM_PREFIX: &str = "boundary=";
/// Content-Disposition header name in lowercase.
pub const HEADER_CONTENT_DISPOSITION: &str = "content-disposition";
/// Content-Type header name in lowercase.
pub const HEADER_CONTENT_TYPE_LOWER: &str = "content-type";
/// Double-dash boundary marker bytes.
pub const DOUBLE_DASH: & = b"--";
/// Header/body CRLFCRLF separator bytes.
pub const CRLF_CRLF: & = b"\r\n\r\n";
/// Sniffed MIME constant for PNG images.
pub const MIME_PNG: &str = "image/png";
/// Sniffed MIME constant for JPEG images.
pub const MIME_JPEG: &str = "image/jpeg";
/// Sniffed MIME constant for GIF images.
pub const MIME_GIF: &str = "image/gif";
/// Sniffed MIME constant for WebP images.
pub const MIME_WEBP: &str = "image/webp";
/// Sniffed MIME constant for PDF documents.
pub const MIME_PDF: &str = "application/pdf";
/// Sniffed MIME constant for ZIP archives.
pub const MIME_ZIP: &str = "application/zip";
/// Sniffed MIME constant for GZIP streams.
pub const MIME_GZIP: &str = "application/gzip";
/// Fallback generic binary MIME type.
pub const MIME_OCTET_STREAM: &str = "application/octet-stream";
/// Error display messages.
pub const ERR_MISSING_BOUNDARY: &str = "missing multipart boundary parameter";
/// Error display message for malformed part structure.
pub const ERR_MALFORMED_BODY: &str = "malformed multipart body";
/// Error display message for exceeding total body cap.
pub const ERR_TOTAL_TOO_LARGE: &str = "multipart body exceeds max_total_bytes";
/// Error display message for exceeding max parts.
pub const ERR_TOO_MANY_PARTS: &str = "multipart upload exceeds max_parts";
/// Error display message for exceeding max files.
pub const ERR_TOO_MANY_FILES: &str = "multipart upload exceeds max_files";
/// Error display message for exceeding single file limit.
pub const ERR_FILE_TOO_LARGE: &str = "uploaded file exceeds max_file_bytes";
/// Error display message for exceeding single text field limit.
pub const ERR_FIELD_TOO_LARGE: &str = "form field exceeds max_field_bytes";
/// Error display message for disallowed MIME type.
pub const ERR_DISALLOWED_MIME: &str = "uploaded file MIME type is disallowed";