aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2024-09-30 11:13:49 -0500
committeramelia squires <[email protected]>2024-09-30 11:13:49 -0500
commitfad6f8b6c1f0d551a733160c417a253616b71f5d (patch)
treef8f73457a0cd1c96191c829843d01dfdbb8138ca /src/net
parent0dd67a9fd8dbf12a693e7007b790d6bffe19b04d (diff)
attatchments
Diffstat (limited to 'src/net')
-rw-r--r--src/net/lua.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/net/lua.c b/src/net/lua.c
index 09c568f..ea03644 100644
--- a/src/net/lua.c
+++ b/src/net/lua.c
@@ -196,6 +196,20 @@ int l_roll(lua_State* L){
//#define bsize 12
int l_sendfile(lua_State* L){
int res_idx = 1;
+ int attachment = 0;
+
+ char* path = (char*)luaL_checkstring(L, 2);
+ char* filename = path;
+
+ if(lua_gettop(L) > 2 && lua_type(L, 3) == LUA_TTABLE){
+ lua_pushstring(L, "attachment");
+ lua_gettable(L, 3);
+ if(!lua_isnil(L, -1)) attachment = lua_toboolean(L, -1);
+
+ lua_pushstring(L, "filename");
+ lua_gettable(L, 3);
+ if(!lua_isnil(L, -1)) filename = (char*)lua_tostring(L, -1);
+ }
lua_pushvalue(L, res_idx);
lua_pushstring(L, "client_fd");
@@ -208,8 +222,6 @@ int l_sendfile(lua_State* L){
lua_gettable(L, -2);
int header = lua_gettop(L);
- char* path = (char*)luaL_checkstring(L, 2);
-
if(access(path, F_OK)) {
p_fatal("file not found"); //TODO: use diff errors here
}
@@ -234,8 +246,14 @@ int l_sendfile(lua_State* L){
char size[256];
sprintf(size, "%li", sz);
luaI_tsets(L, header, "Content-Length", size);
- //todo: allow file name
- //luaI_tsets(L, header, "Content-Disposition", "attachment;");
+
+ if(attachment) {
+ char disp[256];
+ sprintf(disp, "attachment; filename=\"%s\"", filename);
+ luaI_tsets(L, header, "Content-Disposition", disp);
+ } else {
+ luaI_tsets(L, header, "Content-Disposition", "inline;");
+ }
str* r;
i_write_header(L, header, &r, "", 0);