1
0
mirror of https://github.com/wg/wrk synced 2026-06-10 00:55:51 +08:00

3 Commits

3 changed files with 27 additions and 11 deletions
+6 -6
View File
@@ -21,7 +21,7 @@ SRC := wrk.c net.c ssl.c aprintf.c stats.c script.c units.c \
BIN := wrk BIN := wrk
ODIR := obj ODIR := obj
OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) $(ODIR)/bytecode.o
LDIR = deps/luajit/src LDIR = deps/luajit/src
LIBS := -lluajit $(LIBS) LIBS := -lluajit $(LIBS)
@@ -34,25 +34,25 @@ clean:
$(RM) $(BIN) obj/* $(RM) $(BIN) obj/*
@$(MAKE) -C deps/luajit clean @$(MAKE) -C deps/luajit clean
$(BIN): $(OBJ) $(ODIR)/bytecode.o $(BIN): $(OBJ)
@echo LINK $(BIN) @echo LINK $(BIN)
@$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) @$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJ): config.h Makefile | $(ODIR) $(OBJ): config.h Makefile $(LDIR)/libluajit.a | $(ODIR)
$(ODIR): $(LDIR)/libluajit.a $(ODIR):
@mkdir -p $@ @mkdir -p $@
$(ODIR)/bytecode.o: scripts/wrk.lua $(ODIR)/bytecode.o: scripts/wrk.lua
@echo LUAJIT $< @echo LUAJIT $<
@$(SHELL) -c 'cd $(LDIR) && ./luajit -b $(PWD)/$< $(PWD)/$@' @$(SHELL) -c 'cd $(LDIR) && ./luajit -b $(CURDIR)/$< $(CURDIR)/$@'
$(ODIR)/%.o : %.c $(ODIR)/%.o : %.c
@echo CC $< @echo CC $<
@$(CC) $(CFLAGS) -c -o $@ $< @$(CC) $(CFLAGS) -c -o $@ $<
$(LDIR)/libluajit.a: $(LDIR)/libluajit.a:
@echo Building LuaJit... @echo Building LuaJIT...
@$(MAKE) -C $(LDIR) BUILDMODE=static @$(MAKE) -C $(LDIR) BUILDMODE=static
.PHONY: all clean .PHONY: all clean
+20 -4
View File
@@ -9,14 +9,16 @@ local wrk = {
} }
function wrk.format(method, path, headers, body) function wrk.format(method, path, headers, body)
local host = wrk.host
local method = method or wrk.method local method = method or wrk.method
local path = path or wrk.path local path = path or wrk.path
local headers = headers or wrk.headers local headers = headers or wrk.headers
local body = body or wrk.body local body = body or wrk.body
local s = {} 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) headers["Content-Length"] = body and string.len(body)
s[1] = string.format("%s %s HTTP/1.1", method, path) 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") return table.concat(s, "\r\n")
end end
function wrk.init(args) req = wrk.format() end function wrk.init(args)
function wrk.request() return req end 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 init = wrk.init
request = wrk.request request = wrk.request
+1 -1
View File
@@ -14,7 +14,7 @@
#include "script.h" #include "script.h"
#include "http_parser.h" #include "http_parser.h"
#define VERSION "3.0.1" #define VERSION "3.0.3"
#define RECVBUF 8192 #define RECVBUF 8192
#define SAMPLES 100000000 #define SAMPLES 100000000