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