1
0
mirror of https://github.com/wg/wrk synced 2025-01-23 04:02:59 +08:00

fix Host header with port or IPv6 address

This commit is contained in:
Will 2013-11-10 16:16:53 +09:00
parent b03bcb9acc
commit 2a4b64033a
2 changed files with 21 additions and 5 deletions

View File

@ -9,14 +9,16 @@ local wrk = {
}
function wrk.format(method, path, headers, body)
local host = wrk.host
local method = method or wrk.method
local path = path or wrk.path
local headers = headers or wrk.headers
local body = body or wrk.body
local s = {}
headers["Host"] = port and (host .. ":" .. port) or host
if not headers["Host"] then
headers["Host"] = wrk.headers["Host"]
end
headers["Content-Length"] = body and string.len(body)
s[1] = string.format("%s %s HTTP/1.1", method, path)
@ -30,8 +32,22 @@ function wrk.format(method, path, headers, body)
return table.concat(s, "\r\n")
end
function wrk.init(args) req = wrk.format() end
function wrk.request() return req end
function wrk.init(args)
if not wrk.headers["Host"] then
local host = wrk.host
local port = wrk.port
host = host:find(":") and ("[" .. host .. "]") or host
host = port and (host .. ":" .. port) or host
wrk.headers["Host"] = host
end
req = wrk.format()
end
function wrk.request()
return req
end
init = wrk.init
request = wrk.request

View File

@ -14,7 +14,7 @@
#include "script.h"
#include "http_parser.h"
#define VERSION "3.0.1"
#define VERSION "3.0.3"
#define RECVBUF 8192
#define SAMPLES 100000000