| ... | ... | @@ -355,17 +355,19 @@ pub const Response = struct { |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | pub const ResetState = enum { reset, closing }; |
| 359 | |
| 358 | 360 | /// Reset this response to its initial state. This must be called before handling a second request on the same connection. |
| 359 | | pub fn reset(res: *Response) bool { |
| 361 | pub fn reset(res: *Response) ResetState { |
| 360 | 362 | if (res.state == .first) { |
| 361 | 363 | res.state = .start; |
| 362 | | return true; |
| 364 | return .reset; |
| 363 | 365 | } |
| 364 | 366 | |
| 365 | 367 | if (!res.request.parser.done) { |
| 366 | 368 | // If the response wasn't fully read, then we need to close the connection. |
| 367 | 369 | res.connection.conn.closing = true; |
| 368 | | return false; |
| 370 | return .closing; |
| 369 | 371 | } |
| 370 | 372 | |
| 371 | 373 | // A connection is only keep-alive if the Connection header is present and it's value is not "close". |
| ... | ... | @@ -408,7 +410,11 @@ pub const Response = struct { |
| 408 | 410 | .parser = res.request.parser, |
| 409 | 411 | }; |
| 410 | 412 | |
| 411 | | return !res.connection.conn.closing; |
| 413 | if (res.connection.conn.closing) { |
| 414 | return .closing; |
| 415 | } else { |
| 416 | return .reset; |
| 417 | } |
| 412 | 418 | } |
| 413 | 419 | |
| 414 | 420 | pub const DoError = BufferedConnection.WriteError || error{ UnsupportedTransferEncoding, InvalidContentLength }; |
| ... | ... | @@ -699,7 +705,7 @@ pub const HeaderStrategy = union(enum) { |
| 699 | 705 | static: []u8, |
| 700 | 706 | }; |
| 701 | 707 | |
| 702 | | /// Accept a new connection and allocate a Response for it. |
| 708 | /// Accept a new connection. |
| 703 | 709 | pub fn accept(server: *Server, options: HeaderStrategy) AcceptError!Response { |
| 704 | 710 | const in = try server.socket.accept(); |
| 705 | 711 | |