mirror of
https://github.com/wg/wrk
synced 2025-01-23 04:02:59 +08:00
remove dependency on unspecified behavior
This commit is contained in:
parent
051c35fca6
commit
a20969192f
39
src/script.c
39
src/script.c
@ -22,9 +22,9 @@ static int script_thread_newindex(lua_State *);
|
|||||||
static int script_wrk_lookup(lua_State *);
|
static int script_wrk_lookup(lua_State *);
|
||||||
static int script_wrk_connect(lua_State *);
|
static int script_wrk_connect(lua_State *);
|
||||||
|
|
||||||
static void set_fields(lua_State *, int index, const table_field *);
|
static void set_fields(lua_State *, int, const table_field *);
|
||||||
static void set_string(lua_State *, int, char *, char *, size_t);
|
static void set_field(lua_State *, int, char *, int);
|
||||||
static char *get_url_part(char *, struct http_parser_url *, enum http_parser_url_fields, size_t *);
|
static int push_url_part(lua_State *, char *, struct http_parser_url *, enum http_parser_url_fields);
|
||||||
|
|
||||||
static const struct luaL_reg addrlib[] = {
|
static const struct luaL_reg addrlib[] = {
|
||||||
{ "__tostring", script_addr_tostring },
|
{ "__tostring", script_addr_tostring },
|
||||||
@ -60,7 +60,6 @@ lua_State *script_create(char *file, char *url, char **headers) {
|
|||||||
struct http_parser_url parts = {};
|
struct http_parser_url parts = {};
|
||||||
script_parse_url(url, &parts);
|
script_parse_url(url, &parts);
|
||||||
char *path = "/";
|
char *path = "/";
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
if (parts.field_set & (1 << UF_PATH)) {
|
if (parts.field_set & (1 << UF_PATH)) {
|
||||||
path = &url[parts.field_data[UF_PATH].off];
|
path = &url[parts.field_data[UF_PATH].off];
|
||||||
@ -75,9 +74,9 @@ lua_State *script_create(char *file, char *url, char **headers) {
|
|||||||
|
|
||||||
lua_getglobal(L, "wrk");
|
lua_getglobal(L, "wrk");
|
||||||
|
|
||||||
set_string(L, 4, "scheme", get_url_part(url, &parts, UF_SCHEMA, &len), len);
|
set_field(L, 4, "scheme", push_url_part(L, url, &parts, UF_SCHEMA));
|
||||||
set_string(L, 4, "host", get_url_part(url, &parts, UF_HOST, &len), len);
|
set_field(L, 4, "host", push_url_part(L, url, &parts, UF_HOST));
|
||||||
set_string(L, 4, "port", get_url_part(url, &parts, UF_PORT, &len), len);
|
set_field(L, 4, "port", push_url_part(L, url, &parts, UF_PORT));
|
||||||
set_fields(L, 4, fields);
|
set_fields(L, 4, fields);
|
||||||
|
|
||||||
lua_getfield(L, 4, "headers");
|
lua_getfield(L, 4, "headers");
|
||||||
@ -502,20 +501,24 @@ int script_parse_url(char *url, struct http_parser_url *parts) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_url_part(char *url, struct http_parser_url *parts, enum http_parser_url_fields field, size_t *len) {
|
static int push_url_part(lua_State *L, char *url, struct http_parser_url *parts, enum http_parser_url_fields field) {
|
||||||
char *value = NULL;
|
int type = parts->field_set & (1 << field) ? LUA_TSTRING : LUA_TNIL;
|
||||||
if (parts->field_set & (1 << field)) {
|
uint16_t off, len;
|
||||||
value = &url[parts->field_data[field].off];
|
switch (type) {
|
||||||
*len = parts->field_data[field].len;
|
case LUA_TSTRING:
|
||||||
|
off = parts->field_data[field].off;
|
||||||
|
len = parts->field_data[field].len;
|
||||||
|
lua_pushlstring(L, &url[off], len);
|
||||||
|
break;
|
||||||
|
case LUA_TNIL:
|
||||||
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
return value;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_string(lua_State *L, int index, char *field, char *value, size_t len) {
|
static void set_field(lua_State *L, int index, char *field, int type) {
|
||||||
if (value != NULL) {
|
(void) type;
|
||||||
lua_pushlstring(L, value, len);
|
lua_setfield(L, index, field);
|
||||||
lua_setfield(L, index, field);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_fields(lua_State *L, int index, const table_field *fields) {
|
static void set_fields(lua_State *L, int index, const table_field *fields) {
|
||||||
|
Loading…
Reference in New Issue
Block a user