57 static int HttpGetRequestHost(
lua_State *luastate)
66 if (tx->request_hostname == NULL)
70 bstr_ptr(tx->request_hostname), bstr_len(tx->request_hostname));
73 static int HttpGetRequestUriRaw(
lua_State *luastate)
82 if (tx->request_uri == NULL)
86 bstr_ptr(tx->request_uri), bstr_len(tx->request_uri));
89 static int HttpGetRequestUriNormalized(
lua_State *luastate)
112 static int HttpGetRequestLine(
lua_State *luastate)
121 if (tx->request_line == NULL)
125 bstr_ptr(tx->request_line), bstr_len(tx->request_line));
128 static int HttpGetResponseLine(
lua_State *luastate)
137 if (tx->response_line == NULL)
141 bstr_ptr(tx->response_line), bstr_len(tx->response_line));
144 static int HttpGetHeader(
lua_State *luastate,
int dir)
155 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
157 htp_table_t *headers = tx->request_headers;
159 headers = tx->response_headers;
163 htp_header_t *h = (htp_header_t *)htp_table_get_c(headers,
name);
164 if (h == NULL || bstr_len(h->value) == 0)
168 bstr_ptr(h->value), bstr_len(h->value));
171 static int HttpGetRequestHeader(
lua_State *luastate)
173 return HttpGetHeader(luastate, 0 );
176 static int HttpGetResponseHeader(
lua_State *luastate)
178 return HttpGetHeader(luastate, 1 );
181 static int HttpGetRawHeaders(
lua_State *luastate,
int dir)
201 if (raw == NULL || raw_len == 0)
207 static int HttpGetRawRequestHeaders(
lua_State *luastate)
209 return HttpGetRawHeaders(luastate, 0);
212 static int HttpGetRawResponseHeaders(
lua_State *luastate)
214 return HttpGetRawHeaders(luastate, 1);
218 static int HttpGetHeaders(
lua_State *luastate,
int dir)
227 htp_table_t *table = tx->request_headers;
229 table = tx->response_headers;
230 if (tx->request_headers == NULL)
233 lua_newtable(luastate);
234 htp_header_t *h = NULL;
236 size_t no_of_headers = htp_table_size(table);
237 for (; i < no_of_headers; i++) {
238 h = htp_table_get_index(table, i, NULL);
241 lua_settable(luastate, -3);
247 static int HttpGetRequestHeaders(
lua_State *luastate)
249 return HttpGetHeaders(luastate, 0);
253 static int HttpGetResponseHeaders(
lua_State *luastate)
255 return HttpGetHeaders(luastate, 1);
258 static int HttpGetBody(
lua_State *luastate,
int dir)
278 if (body->
first == NULL)
283 lua_newtable(luastate);
284 while (chunk != NULL) {
285 lua_pushinteger(luastate, index);
287 const uint8_t *data = NULL;
288 uint32_t data_len = 0;
292 lua_settable(luastate, -3);
299 lua_pushinteger(luastate, body->
first->
sbseg.stream_offset);
300 lua_pushinteger(luastate, body->
last->
sbseg.stream_offset + body->
last->
sbseg.segment_len);
307 static int HttpGetRequestBody(
lua_State *luastate)
309 return HttpGetBody(luastate, 0);
312 static int HttpGetResponseBody(
lua_State *luastate)
314 return HttpGetBody(luastate, 1);
321 lua_pushcfunction(luastate, HttpGetRequestHeader);
322 lua_setglobal(luastate,
"HttpGetRequestHeader");
323 lua_pushcfunction(luastate, HttpGetResponseHeader);
324 lua_setglobal(luastate,
"HttpGetResponseHeader");
325 lua_pushcfunction(luastate, HttpGetRequestLine);
326 lua_setglobal(luastate,
"HttpGetRequestLine");
327 lua_pushcfunction(luastate, HttpGetResponseLine);
328 lua_setglobal(luastate,
"HttpGetResponseLine");
329 lua_pushcfunction(luastate, HttpGetRawRequestHeaders);
330 lua_setglobal(luastate,
"HttpGetRawRequestHeaders");
331 lua_pushcfunction(luastate, HttpGetRawResponseHeaders);
332 lua_setglobal(luastate,
"HttpGetRawResponseHeaders");
333 lua_pushcfunction(luastate, HttpGetRequestUriRaw);
334 lua_setglobal(luastate,
"HttpGetRequestUriRaw");
335 lua_pushcfunction(luastate, HttpGetRequestUriNormalized);
336 lua_setglobal(luastate,
"HttpGetRequestUriNormalized");
337 lua_pushcfunction(luastate, HttpGetRequestHeaders);
338 lua_setglobal(luastate,
"HttpGetRequestHeaders");
339 lua_pushcfunction(luastate, HttpGetResponseHeaders);
340 lua_setglobal(luastate,
"HttpGetResponseHeaders");
341 lua_pushcfunction(luastate, HttpGetRequestHost);
342 lua_setglobal(luastate,
"HttpGetRequestHost");
344 lua_pushcfunction(luastate, HttpGetRequestBody);
345 lua_setglobal(luastate,
"HttpGetRequestBody");
346 lua_pushcfunction(luastate, HttpGetResponseBody);
347 lua_setglobal(luastate,
"HttpGetResponseBody");