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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//! Protocol constants for Braid-HTTP.
//!
//! This module defines standard header names, status codes, merge type identifiers,
//! and other protocol constants used throughout the Braid-HTTP implementation.
//!
//! # Organization
//!
//! ```text
//! constants/
//! ├── Top-level - Common status codes (STATUS_SUBSCRIPTION, etc.)
//! ├── status - All HTTP status codes used by Braid
//! ├── headers - All Braid protocol header names (typed)
//! └── merge_types - Merge type identifiers
//! ```
//!
//! # Status Codes
//!
//! | Code | Constant | Description |
//! |------|----------|-------------|
//! | 200 | `status::OK` | Standard response |
//! | 206 | `status::PARTIAL_CONTENT` | Range-based patches |
//! | 209 | `STATUS_SUBSCRIPTION` | Subscription update |
//! | 293 | `STATUS_MERGE_CONFLICT` | Version conflicts |
//! | 410 | `STATUS_GONE` | History dropped |
//! | 416 | `STATUS_RANGE_NOT_SATISFIABLE` | Invalid range |
//!
//! # Examples
//!
//! ```
//! use braid_http_rs::core::protocol;
//! use braid_http_rs::core::protocol::constants::{headers, merge_types};
//!
//! // Use top-level constants
//! let status = 209u16;
//! if status == protocol::STATUS_SUBSCRIPTION {
//! println!("Subscription response");
//! }
//!
//! // Use module constants
//! if status == protocol::status::SUBSCRIPTION {
//! println!("Same as above");
//! }
//!
//! // Use header name constants
//! let header_name = headers::VERSION;
//! assert_eq!(header_name, "Version");
//!
//! // Use merge type constants
//! let merge_type = merge_types::DIAMOND;
//! assert_eq!(merge_type, "diamond");
//! ```
//!
//! # Specification
//!
//! See [draft-toomim-httpbis-braid-http-04]:
//!
//! - **Section 2**: Versioning and merge types
//! - **Section 3**: Patches and Content-Range
//! - **Section 4**: Subscriptions and status codes
//!
//! [draft-toomim-httpbis-braid-http-04]: https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http
// =============================================================================
// Top-Level Status Code Constants
// =============================================================================
/// HTTP status code for subscription updates (Section 4).
///
/// The server sends this status code (209) when responding to a subscription
/// request. The connection remains open and updates are streamed as they occur.
///
/// # Example
///
/// ```
/// use braid_http_rs::core::protocol::STATUS_SUBSCRIPTION;
///
/// assert_eq!(STATUS_SUBSCRIPTION, 209);
/// ```
pub const STATUS_SUBSCRIPTION: u16 = 209;
/// HTTP status code for merge conflicts (Section 2.2).
///
/// The server sends this status code (293) when it detects conflicting versions
/// during a merge operation. The client should apply the merge strategy specified
/// by the Merge-Type header to resolve the conflict.
///
/// # Example
///
/// ```
/// use braid_http_rs::core::protocol::STATUS_MERGE_CONFLICT;
///
/// assert_eq!(STATUS_MERGE_CONFLICT, 293);
/// ```
pub const STATUS_MERGE_CONFLICT: u16 = 293;
/// HTTP status code for history dropped (Section 4.5).
///
/// The server sends this status code (410 Gone) when it has discarded version
/// history before the requested version. The client must restart synchronization
/// from scratch by clearing its local state.
pub const STATUS_GONE: u16 = 410;
/// HTTP status code for range not satisfiable.
///
/// The server sends this status code (416) when the requested Content-Range
/// is invalid or cannot be satisfied (e.g., range exceeds resource size).
pub const STATUS_RANGE_NOT_SATISFIABLE: u16 = 416;
// =============================================================================
// Status Code Module
// =============================================================================
/// Standard HTTP status codes used by Braid-HTTP.
///
/// # Example
///
/// ```
/// use braid_http_rs::core::protocol::status;
///
/// assert_eq!(status::OK, 200);
/// assert_eq!(status::SUBSCRIPTION, 209);
/// ```
// =============================================================================
// Header Names Module
// =============================================================================
/// Braid protocol header names.
///
/// Use these constants when setting or reading Braid-specific headers.
/// These are typed `axum::http::HeaderName` constants for zero-copy usage.
///
/// # Example
///
/// ```
/// use braid_http_rs::core::protocol::constants::headers;
///
/// assert_eq!(headers::VERSION, "version");
/// assert_eq!(headers::SUBSCRIBE, "subscribe");
/// ```
// =============================================================================
// Merge Types Module
// =============================================================================
/// Merge type identifiers for conflict resolution.
///
/// # Example
///
/// ```
/// use braid_http_rs::core::protocol::merge_types;
///
/// assert_eq!(merge_types::DIAMOND, "diamond");
/// assert_eq!(merge_types::SYNC9, "sync9");
/// ```
// =============================================================================
// Media Types Module
// =============================================================================
/// Braid protocol media types.