Software /
code /
prosody
Comparison
net/http.lua @ 11661:735b8f4a6d7e
net.http: Send entire HTTP request header as one write
When opportunistic writes are enabled this reduces the number of
syscalls and TCP packets sent on the wire.
Experiments with TCP Fast Open made this even more obvious.
That table trick probably wasn't as efficient. Lua generates bytecode
for a table with zero array slots and space for two entries in the hash
part, plus code to set [2] and [4]. I didn't verify but I suspect it
would have had to resize the table when setting [1] and [3], although
probably only once. Concatenating the strings directly in Lua is easier
to read and involves no extra table or function call.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 08 Jul 2021 18:21:59 +0200 |
parent | 11220:9b25eecde9e6 |
child | 11749:83d6d6a70edf |
comparison
equal
deleted
inserted
replaced
11660:68f0196ece2a | 11661:735b8f4a6d7e |
---|---|
162 local request_line = { req.method or "GET", " ", req.path, " HTTP/1.1\r\n" }; | 162 local request_line = { req.method or "GET", " ", req.path, " HTTP/1.1\r\n" }; |
163 if req.query then | 163 if req.query then |
164 t_insert(request_line, 4, "?"..req.query); | 164 t_insert(request_line, 4, "?"..req.query); |
165 end | 165 end |
166 | 166 |
167 for k, v in pairs(req.headers) do | |
168 t_insert(request_line, k .. ": " .. v .. "\r\n"); | |
169 end | |
170 t_insert(request_line, "\r\n") | |
167 conn:write(t_concat(request_line)); | 171 conn:write(t_concat(request_line)); |
168 local t = { [2] = ": ", [4] = "\r\n" }; | |
169 for k, v in pairs(req.headers) do | |
170 t[1], t[3] = k, v; | |
171 conn:write(t_concat(t)); | |
172 end | |
173 conn:write("\r\n"); | |
174 | 172 |
175 if req.body then | 173 if req.body then |
176 conn:write(req.body); | 174 conn:write(req.body); |
177 end | 175 end |
178 end | 176 end |