1
1
pub const Client = @import ("http/Client.zig" );
2
2
3
+ pub const Version = enum {
4
+ @"HTTP/1.0" ,
5
+ @"HTTP/1.1" ,
6
+ };
7
+
3
8
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
4
9
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definiton
5
10
/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH
@@ -220,14 +225,13 @@ pub const Status = enum(u10) {
220
225
server_error ,
221
226
};
222
227
223
- pub fn class (self : Status ) ? Class {
228
+ pub fn class (self : Status ) Class {
224
229
return switch (@enumToInt (self )) {
225
230
100... 199 = > .informational ,
226
231
200... 299 = > .success ,
227
232
300... 399 = > .redirect ,
228
233
400... 499 = > .client_error ,
229
- 500... 599 = > .server_error ,
230
- else = > null ,
234
+ else = > .server_error ,
231
235
};
232
236
}
233
237
@@ -242,60 +246,10 @@ pub const Status = enum(u10) {
242
246
}
243
247
};
244
248
245
- pub const Headers = struct {
246
- state : State = .start ,
247
- invalid_index : u32 = undefined ,
248
-
249
- pub const State = enum { invalid , start , line , nl_r , nl_n , nl2_r , finished };
250
-
251
- /// Returns how many bytes are processed into headers. Always less than or
252
- /// equal to bytes.len. If the amount returned is less than bytes.len, it
253
- /// means the headers ended and the first byte after the double \r\n\r\n is
254
- /// located at `bytes[result]`.
255
- pub fn feed (h : * Headers , bytes : []const u8 ) usize {
256
- for (bytes ) | b , i | {
257
- switch (h .state ) {
258
- .start = > switch (b ) {
259
- '\r ' = > h .state = .nl_r ,
260
- '\n ' = > return invalid (h , i ),
261
- else = > {},
262
- },
263
- .nl_r = > switch (b ) {
264
- '\n ' = > h .state = .nl_n ,
265
- else = > return invalid (h , i ),
266
- },
267
- .nl_n = > switch (b ) {
268
- '\r ' = > h .state = .nl2_r ,
269
- else = > h .state = .line ,
270
- },
271
- .nl2_r = > switch (b ) {
272
- '\n ' = > h .state = .finished ,
273
- else = > return invalid (h , i ),
274
- },
275
- .line = > switch (b ) {
276
- '\r ' = > h .state = .nl_r ,
277
- '\n ' = > return invalid (h , i ),
278
- else = > {},
279
- },
280
- .invalid = > return i ,
281
- .finished = > return i ,
282
- }
283
- }
284
- return bytes .len ;
285
- }
286
-
287
- fn invalid (h : * Headers , i : usize ) usize {
288
- h .invalid_index = @intCast (u32 , i );
289
- h .state = .invalid ;
290
- return i ;
291
- }
292
- };
293
-
294
249
const std = @import ("std.zig" );
295
250
296
251
test {
297
252
_ = Client ;
298
253
_ = Method ;
299
254
_ = Status ;
300
- _ = Headers ;
301
255
}
0 commit comments