authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-18 20:26:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-23 02:37:11-07:00
logc7fc2d76ce2b9b1cedd6d71232f31ba9556f05d9
treeed9bc760804e8b488e38c053778be9d409b1facc
parent6129ecd4fe88e14531db98866c92c4a5660849ee

std.http.Server: move closing bool

It does not belong in the Connection struct

2 files changed, 5 insertions(+), 6 deletions(-)

lib/std/http/Server.zig+5-4
...@@ -4,6 +4,7 @@ reason: ?[]const u8,...@@ -4,6 +4,7 @@ reason: ?[]const u8,
4transfer_encoding: ResponseTransfer,4transfer_encoding: ResponseTransfer,
5keep_alive: bool,5keep_alive: bool,
6connection: Connection,6connection: Connection,
7connection_closing: bool,
78
8/// Externally-owned; must outlive the Server.9/// Externally-owned; must outlive the Server.
9extra_headers: []const http.Header,10extra_headers: []const http.Header,
...@@ -25,11 +26,11 @@ pub fn init(connection: std.net.Server.Connection, options: Server.Request.InitO...@@ -25,11 +26,11 @@ pub fn init(connection: std.net.Server.Connection, options: Server.Request.InitO
25 .connection = .{26 .connection = .{
26 .stream = connection.stream,27 .stream = connection.stream,
27 .protocol = .plain,28 .protocol = .plain,
28 .closing = true,
29 .read_buf = undefined,29 .read_buf = undefined,
30 .read_start = 0,30 .read_start = 0,
31 .read_end = 0,31 .read_end = 0,
32 },32 },
33 .connection_closing = true,
33 .request = Server.Request.init(options),34 .request = Server.Request.init(options),
34 .version = .@"HTTP/1.1",35 .version = .@"HTTP/1.1",
35 .status = .ok,36 .status = .ok,
...@@ -232,7 +233,7 @@ pub fn reset(res: *Server) ResetState {...@@ -232,7 +233,7 @@ pub fn reset(res: *Server) ResetState {
232233
233 if (!res.request.parser.done) {234 if (!res.request.parser.done) {
234 // If the response wasn't fully read, then we need to close the connection.235 // If the response wasn't fully read, then we need to close the connection.
235 res.connection.closing = true;236 res.connection_closing = true;
236 return .closing;237 return .closing;
237 }238 }
238239
...@@ -240,7 +241,7 @@ pub fn reset(res: *Server) ResetState {...@@ -240,7 +241,7 @@ pub fn reset(res: *Server) ResetState {
240 // and its value is not "close". The server and client must both agree.241 // and its value is not "close". The server and client must both agree.
241 //242 //
242 // send() defaults to using keep-alive if the client requests it.243 // send() defaults to using keep-alive if the client requests it.
243 res.connection.closing = !res.keep_alive or !res.request.keep_alive;244 res.connection_closing = !res.keep_alive or !res.request.keep_alive;
244245
245 res.state = .start;246 res.state = .start;
246 res.version = .@"HTTP/1.1";247 res.version = .@"HTTP/1.1";
...@@ -253,7 +254,7 @@ pub fn reset(res: *Server) ResetState {...@@ -253,7 +254,7 @@ pub fn reset(res: *Server) ResetState {
253 .client_header_buffer = res.request.parser.header_bytes_buffer,254 .client_header_buffer = res.request.parser.header_bytes_buffer,
254 });255 });
255256
256 return if (res.connection.closing) .closing else .reset;257 return if (res.connection_closing) .closing else .reset;
257}258}
258259
259pub const SendError = Connection.WriteError || error{260pub const SendError = Connection.WriteError || error{
lib/std/http/Server/Connection.zig-2
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1stream: std.net.Stream,1stream: std.net.Stream,
2protocol: Protocol,2protocol: Protocol,
33
4closing: bool,
5
6read_buf: [buffer_size]u8,4read_buf: [buffer_size]u8,
7read_start: u16,5read_start: u16,
8read_end: u16,6read_end: u16,