aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorame <[email protected]>2024-09-30 02:06:47 -0500
committerame <[email protected]>2024-09-30 02:06:47 -0500
commit2a7f5c95a5406b6de215dbc24a733e29d609d20f (patch)
tree6409e4b3c43b17e9c73d2b29193450712fb63190 /src/net
parente9cb2e0f75cbfa6bde188b9e043ebfd8d30b9451 (diff)
cookies, sendfile fixes, and local var tests
Diffstat (limited to 'src/net')
-rw-r--r--src/net/lua.c24
-rw-r--r--src/net/lua.h1
2 files changed, 16 insertions, 9 deletions
diff --git a/src/net/lua.c b/src/net/lua.c
index 2995326..9600189 100644
--- a/src/net/lua.c
+++ b/src/net/lua.c
@@ -182,7 +182,8 @@ int l_roll(lua_State* L){
return 1;
}
-#define bsize 512
+#define bsize 32768
+//#define bsize 12
int l_sendfile(lua_State* L){
int res_idx = 1;
@@ -206,20 +207,27 @@ int l_sendfile(lua_State* L){
p_fatal("missing permissions");
}
- str* r;
- i_write_header(L, header, &r, "", 0);
- send(client_fd, r->c, r->len, 0);
- str_free(r);
-
char* buffer = calloc(sizeof* buffer, bsize + 1);
FILE* fp = fopen(path, "rb");
fseek(fp, 0L, SEEK_END);
size_t sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
+
+ 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;");
+
+ str* r;
+ i_write_header(L, header, &r, "", 0);
+ send(client_fd, r->c, r->len, 0);
+ str_free(r);
- for(int i = 0; i < sz; i += bsize){
+ for(size_t i = 0; i < sz; i += bsize){
fread(buffer, sizeof * buffer, bsize, fp);
- send(client_fd, buffer, bsize > sz - i ? sz - i : bsize, 0);
+ if(send(client_fd, buffer, bsize > sz - i ? sz - i : bsize, 0) == -1)
+ break;
}
free(buffer);
diff --git a/src/net/lua.h b/src/net/lua.h
index 794e45f..d3c2371 100644
--- a/src/net/lua.h
+++ b/src/net/lua.h
@@ -4,5 +4,4 @@ int l_write(lua_State* L);
int l_send(lua_State* L);
int l_close(lua_State* L);
int l_roll(lua_State* L);
-#define bsize 512
int l_sendfile(lua_State* L);