MCPcopy Create free account
hub / github.com/apache/httpd / lua_ap_requestbody

Function lua_ap_requestbody

modules/lua/lua_request.c:456–507  ·  view source on GitHub ↗

* lua_ap_requestbody; r:requestbody([filename]) - Reads or stores the request * body */

Source from the content-addressed store, hash-verified

454 * body
455 */
456static int lua_ap_requestbody(lua_State *L)
457{
458 const char *filename;
459 request_rec *r;
460 apr_off_t maxSize;
461
462 r = ap_lua_check_request_rec(L, 1);
463 filename = luaL_optstring(L, 2, 0);
464 maxSize = (apr_off_t)luaL_optinteger(L, 3, 0);
465
466 if (r) {
467 apr_off_t size;
468 if (maxSize > 0 && r->remaining > maxSize) {
469 lua_pushnil(L);
470 lua_pushliteral(L, "Request body was larger than the permitted size.");
471 return 2;
472 }
473 if (r->method_number != M_POST && r->method_number != M_PUT)
474 return (0);
475 if (!filename) {
476 const char *data;
477
478 if (lua_read_body(r, &data, &size, maxSize) != OK)
479 return (0);
480
481 lua_pushlstring(L, data, (size_t) size);
482 lua_pushinteger(L, (lua_Integer) size);
483 return (2);
484 } else {
485 apr_status_t rc;
486 apr_file_t *file;
487
488 rc = apr_file_open(&file, filename, APR_CREATE | APR_FOPEN_WRITE,
489 APR_FPROT_OS_DEFAULT, r->pool);
490 lua_settop(L, 0);
491 if (rc == APR_SUCCESS) {
492 rc = lua_write_body(r, file, &size);
493 apr_file_close(file);
494 if (rc != OK) {
495 lua_pushboolean(L, 0);
496 return 1;
497 }
498 lua_pushinteger(L, (lua_Integer) size);
499 return (1);
500 } else
501 lua_pushboolean(L, 0);
502 return (1);
503 }
504 }
505
506 return (0);
507}
508
509/* wrap ap_rputs as r:puts(String) */
510static int req_puts(lua_State *L)

Callers

nothing calls this directly

Calls 3

lua_read_bodyFunction · 0.85
lua_write_bodyFunction · 0.85
ap_lua_check_request_recFunction · 0.70

Tested by

no test coverage detected