diff options
| -rw-r--r-- | docs/net/listen.md | 50 | ||||
| -rw-r--r-- | library/lullaby/net.lua | 4 | ||||
| -rw-r--r-- | readme.md | 7 | ||||
| -rw-r--r-- | src/lua.c | 10 | ||||
| -rw-r--r-- | src/lua.h | 3 | ||||
| -rw-r--r-- | src/net.c | 7 | ||||
| -rw-r--r-- | src/net.h | 2 | ||||
| -rw-r--r-- | src/net/common.h | 9 | ||||
| -rw-r--r-- | src/net/lua.c | 98 | ||||
| -rw-r--r-- | src/net/lua.h | 2 | ||||
| -rw-r--r-- | src/net/luai.c | 152 | ||||
| -rw-r--r-- | src/net/util.c | 52 | ||||
| -rw-r--r-- | src/net/util.h | 5 | ||||
| -rw-r--r-- | src/net/websocket.c | 2 | ||||
| -rw-r--r-- | src/types/str.c | 9 | ||||
| -rw-r--r-- | src/types/str.h | 2 | ||||
| -rw-r--r-- | src/util.c | 2 | ||||
| -rw-r--r-- | src/util.h | 2 | ||||
| -rw-r--r-- | tests/old/net2.lua | 8 |
19 files changed, 219 insertions, 207 deletions
diff --git a/docs/net/listen.md b/docs/net/listen.md index 420a609..f696cec 100644 --- a/docs/net/listen.md +++ b/docs/net/listen.md @@ -2,6 +2,8 @@ net.listen(function, port)
+currently does not work with any transfer-encoding!!
+
(intentionally styled after expressjs:3)
the function will be ran on initilization, the argument has info on the server and functions to set it up
@@ -210,7 +212,7 @@ calling this will update, add or delete some res or req values/functions removes:
-req:roll
+req:load
adds:
@@ -244,48 +246,32 @@ these can, of course be used with wildcards however you want /*/{user}/id would match /a/b/c/meow/id with req.parameters.user being equal to meow
-### req:roll
+### req:load
+
+req:load(bytes?)
+
+when no parameters are passed (or bytes is -1) the whole request will be read
-req:roll(bytes?)
+otherwise, that many bytes will be read from the client and parsed
-> this will be changed to be a stream internally, see common.md
+when the content has just a body and no files, the bytes will be loaded as they are parsed into req.body
-when bytes is null it will read as much as possible (may not be the full request)
+when the content contains files, the files will be added to req.files when the full file is parsed (they will not be partial)
will update req according to how the bytes needed to be parsed, returns the number of bytes read (not necessarily parsed), 0 if there
is no more ready data, -1 if all data has been read, and any other values \< -1 is a recv error (add 1 to the error code)
+returns 1 when there is still more data to parse
+returns 0 when there is not more data to parse
+may return an error
+
> waiting on a rewrite for this, all that will be changed will be how errors are returned
```lua
--when a request contains "hello world"
req.body --"hello"
-req:roll(30) --does not matter if you go over, returns 7 (probably)
+req:load(30) --does not matter if you go over, returns 7 (probably)
req.body --"hello world"
-req:roll(50) --returns -1, no more to read
---req.Body has not been updated
+req:load(50) --returns -1, no more to read
+--req.body has not been updated
```
-
-can have unique results with files (this example is not perfect, roll could read less than 2 bytes, and this does not account for newlines)
-
-```lua
---sent a file ina request to the server, where the boundary is 'abcd':
--- ---abcd
--- (header junk, file name and stuff)
---
--- wowa
--- --
--- --ab
--- --abcd
-
---when the line 'wowa' has just been read, using roll for less than two will not update the file
-req.body -- (...)"wowa"
-req:roll(2)
-req.body -- (...)"wowa" (unchanged)
---any lines that contain just the boundary and -'s will be put in a seperate buffer until it ends or breaks
---a previous condition, then it will be added
-req:roll(2)
-req.body -- (...)"wowa\n--"
---and now "--" (from the next line) is in the possible boundary buffer, it ends in "ab" so it will be added to the main body
-```
-
diff --git a/library/lullaby/net.lua b/library/lullaby/net.lua index e9bab4b..7ec15f3 100644 --- a/library/lullaby/net.lua +++ b/library/lullaby/net.lua @@ -65,10 +65,10 @@ res_table.open = true ---@class req-table local req_table = {} ----"roll" the request forward +---loads the request body/files ---@param T req-table ---@param bytes integer | nil -function req_table.roll(T, bytes) end +function req_table.load(T, bytes) end ---list of parameters in route req_table.parameters = {} @@ -9,11 +9,10 @@ heres an example of a webserver to return a [sha0](https://en.wikipedia.org/wiki <blockquote>
```lua
---(this is in tests/net2.lua)
+--(this is in tests/old/net2.lua)
net = require "lullaby.net"
crypto = require "lullaby.crypto"
local port = 8080
-MAX_LENGTH = 2048
net.listen(function(server)
@@ -21,8 +20,8 @@ net.listen(function(server) server:POST("/", function(res, req)
--creates a sha0 hash object
local hash = crypto.sha0()
- --loads an extra 2048 characters from the request body (the body is not guaranteed to be >= 2048 characters, reasoning in docs)
- req:roll(MAX_LENGTH)
+
+ req:load()
--incremental hashes allow updating via addition, in this case adding the body and getting a string from it
hash = (hash + req.Body):final()
@@ -14,6 +14,16 @@ int luaI_nothing(lua_State* L){ return 0;
}
+void luaI_fromparray(lua_State* L, int table_idx, parray_t* table, int strval){
+ for(int i = 0; i != table->len; i++){
+ if(table->P[i].value == NULL) lua_pushboolean(L, 1);
+ else if(strval) lua_pushlstring(L, ((str*)table->P[i].value)->c, ((str*)table->P[i].value)->len);
+ else lua_pushstring(L, (char*)table->P[i].value);
+
+ lua_setfield(L, table_idx, table->P[i].key->c);
+ }
+}
+
int luaI_lowercase_index(lua_State* L){
if(lua_type(L, 2) == LUA_TSTRING){
str* s = str_init(lua_tostring(L, 2));
@@ -4,6 +4,7 @@ #include <stdlib.h>
#include <stdint.h>
#include "types/str.h"
+#include "types/parray.h"
#ifndef __lua_h
#define __lua_h
@@ -27,6 +28,8 @@ enum table_cache { #define GIT_COMMIT "unknown"
#endif
+void luaI_fromparray(lua_State* L, int table_idx, parray_t* table, int strval);
+
int luaI_lowercase_index(lua_State* L);
int luaI_lowercase_newindex(lua_State* L);
@@ -777,7 +777,7 @@ void* handle_client(void *_arg){ luaI_tseti(L, req_idx, "_bytes", bite - header_eof - 4);
//luaI_tseti(L, req_idx, "client_fd", client_fd);
- luaI_tsetcf(L, req_idx, "roll", l_roll);
+ luaI_tsetcf(L, req_idx, "load", l_load);
luaI_tsetv(L, res_idx, "req", req_idx);
luaI_tsetv(L, req_idx, "res", res_idx);
@@ -874,9 +874,10 @@ net_end: str_free(parsed_path.path);
parray_clear(parsed_path.query, STR);
- if(file_cont->boundary != NULL) str_free(file_cont->current);
+ if(file_cont->current != NULL) str_free(file_cont->current);
if(file_cont->boundary != NULL) str_free(file_cont->boundary);
- if(file_cont->boundary_id != NULL) str_free(file_cont->boundary_id);
+ if(file_cont->line != NULL) str_free(file_cont->line);
+ //if(file_cont->boundary_id != NULL) str_free(file_cont->boundary_id);
free(file_cont);
}
@@ -24,8 +24,6 @@ int l_wss(lua_State*); int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof, int* state);
-int parse_header(char* buffer, int header_eof, parray_t** _table);
-
void i_write_header(lua_State* L, int header_top, str** _resp, char* content, size_t len);
void client_fd_errors(int client_fd);
diff --git a/src/net/common.h b/src/net/common.h index 6d2f625..ee8f77a 100644 --- a/src/net/common.h +++ b/src/net/common.h @@ -22,18 +22,19 @@ #define max_con 200 //2^42 #define MAX_HEADER_SIZE (1<<20) -#define BUFFER_SIZE 20000 +#define BUFFER_SIZE 210000 +//00 #define HTTP_BUFFER_SIZE 4098 #define max_content_length 200000 enum file_status { - _ignore, BARRIER_READ, FILE_HEADER, FILE_BODY, NORMAL + //_ignore, BARRIER_READ, FILE_HEADER, FILE_BODY, NORMAL + _ignore, BARRIER_START, BARRIER_END, NORMAL }; struct file_parse { enum file_status status; - str *current, *old, *boundary, *boundary_id; - int dash_count, table_idx; + str *current, *old, *boundary, *line; }; struct net_data { diff --git a/src/net/lua.c b/src/net/lua.c index 025828b..5d178a5 100644 --- a/src/net/lua.c +++ b/src/net/lua.c @@ -137,81 +137,75 @@ int l_stop(lua_State* L){ return 0; } -int l_roll(lua_State* L){ - int64_t alen; - if(lua_gettop(L) > 2) { +int l_load(lua_State* L){ + ssize_t alen; + if(lua_gettop(L) >= 2) { alen = luaL_checkinteger(L, 2); } else { alen = -1; } - lua_pushvalue(L, 1); - lua_pushstring(L, "_bytes"); - lua_gettable(L, 1); + lua_getfield(L, 1, "_bytes"); int64_t bytes = luaL_checkinteger(L, -1); - lua_pushstring(L, "content-length"); - lua_gettable(L, 1); - if(lua_type(L, -1) == LUA_TNIL) { - lua_pushinteger(L, -1); + lua_getfield(L, 1, "content-length"); + luaI_assert(L, lua_type(L, -1) != LUA_TNIL); + uint64_t content_length = strtol(luaL_checkstring(L, -1), NULL, 10); + + if(bytes >= content_length){ + lua_pushinteger(L, 0); return 1; } - uint64_t content_length = strtol(luaL_checkstring(L, -1), NULL, 10); - lua_pushstring(L, "_data"); - lua_gettable(L, 1); - struct file_parse* data = (void*)lua_topointer(L, -1); lua_getfield(L, 1, "res"); - lua_pushstring(L, "_"); - lua_gettable(L, -2); + lua_getfield(L, -1, "_"); struct net_data* ctx = lua_touserdata(L, -1); - client_fd_errors(ctx->sock); + lua_getfield(L, 1, "_data"); + struct file_parse* data = lua_touserdata(L, -1); - //fd_set rfd; - //FD_ZERO(&rfd); - //FD_SET(client_fd, &rfd); - //printf("* %li / %li\n", bytes, content_length); - if(bytes >= content_length){ - lua_pushinteger(L, -1); - return 1; - } + client_fd_errors(ctx->sock); - /*if(select(client_fd+1, &rfd, NULL, NULL, &((struct timeval){.tv_sec = 0, .tv_usec = 0})) == 0){ - lua_pushinteger(L, 0); - return 1; - }*/ + lua_getfield(L, 1, "body"); + int body_idx = lua_gettop(L); + lua_getfield(L, 1, "files"); + int files_idx = lua_gettop(L); + if(alen == -1) str_loadatleast(data->current, content_length); + char* buffer = malloc(sizeof * buffer * BUFFER_SIZE); + ssize_t total = bytes; + int over = 1; - //time_start(recv) if(alen == -1) alen = content_length - bytes; - char* buffer = malloc(alen * sizeof * buffer); - int r = net_ctx_read(ctx, buffer, alen); - if(r <= 0){ - lua_pushinteger(L, r - 1); - return 1; - } - //time_end("recv", recv) + else alen = bytes + alen; - lua_pushstring(L, "_bytes"); - lua_pushinteger(L, bytes + r); - lua_settable(L, 1); + for(;total < alen;){ + ssize_t read = BUFFER_SIZE; + if(total + BUFFER_SIZE > alen) read = alen - total; - lua_pushstring(L, "body"); - lua_gettable(L, 1); - int body_idx = lua_gettop(L); + memset(buffer, 0, BUFFER_SIZE); - lua_pushstring(L, "files"); - lua_gettable(L, 1); - int files_idx = lua_gettop(L); - //time_start(parse) - http_body_parse(L, &files_idx, &body_idx, buffer, NULL, r, data); - //time_end("parse", parse) - luaI_tsetv(L, 1, "body", body_idx); - luaI_tsetv(L, 1, "files", files_idx); + ssize_t out = net_ctx_read(ctx, buffer, read); + + if(out == 0) { + over = 0; + break; + } + if(out == -1) { + luaI_error(L, -2, "net read error"); + } + + total += out; + + http_body_parse(L, &files_idx, &body_idx, buffer, NULL, out, data); + } + + lua_pushinteger(L, total); + lua_setfield(L, 1, "_bytes"); free(buffer); - lua_pushinteger(L, r); + + lua_pushinteger(L, over); return 1; } diff --git a/src/net/lua.h b/src/net/lua.h index ef4c0e4..8aaa4a6 100644 --- a/src/net/lua.h +++ b/src/net/lua.h @@ -5,6 +5,6 @@ int l_send(lua_State* L); int l_neterror(lua_State* L); int l_close(lua_State* L); int l_stop(lua_State* L); -int l_roll(lua_State* L); +int l_load(lua_State* L); int l_sendfile(lua_State* L); int l_connection_upgrade(lua_State* L); diff --git a/src/net/luai.c b/src/net/luai.c index 9c320a0..5e1d004 100644 --- a/src/net/luai.c +++ b/src/net/luai.c @@ -48,14 +48,13 @@ int http_body_parse(lua_State* L, int* files_idx, int* body_idx, char* buffer, s parray_t* par = parray_init(); gen_parse(content_type->c, content_type->len, &par); content.boundary = parray_pop(par, "boundary"); - content.status = content.boundary == NULL?BARRIER_READ:NORMAL; - content.dash_count = 0; + content.status = content.boundary != NULL?BARRIER_START:NORMAL; content.current = str_init(""); - content.table_idx = lua_gettop(L); - content.boundary_id = str_init(""); + content.line = str_init(""); parray_clear(par, STR); } + if(content.status == NORMAL){ lua_pushvalue(L, *body_idx); lua_pushlstring(L, buffer, blen); @@ -63,82 +62,75 @@ int http_body_parse(lua_State* L, int* files_idx, int* body_idx, char* buffer, s *body_idx = lua_gettop(L); } else { file_start:; - if(content.status == BARRIER_READ){ - for(int i = 0; i != blen; i++){ - if(*buffer == '\r'){ - content.status = FILE_HEADER; - buffer += 2; - blen -= i + 2; - - content.table_idx = lua_rawlen(L, *files_idx) + 1; - lua_pushinteger(L, content.table_idx); - lua_newtable(L); - lua_settable(L, *files_idx); - break; - } - str_pushl(content.boundary_id, buffer, 1); - buffer++; - } - } - lua_pushvalue(L, *files_idx); - lua_pushinteger(L, content.table_idx); - lua_gettable(L, -2); - int rfiles_idx = lua_gettop(L); - if(content.status == FILE_HEADER){ - for(int i = 0; i < blen; i++){ - - if(buffer[i] == ':'){ - content.old = content.current; - content.current = str_init(""); - } else if(buffer[i] == '\n'){ - if(content.current->len == 0){ - content.status = FILE_BODY; - - buffer += i + 1; - blen -= i + 1; - - content.old = NULL; - str_free(content.current); - content.current = str_init(""); - break; - } -#warning "error here" - luaI_tsets(L, rfiles_idx, content.old->c, content.current->c); - - str_free(content.old); - content.old = NULL; - str_clear(content.current); - } else if(buffer[i] != '\r' && !(buffer[i] == ' ' && content.current->len == 0)) str_pushl(content.current, buffer + i, 1); - } - } - - if(content.status == FILE_BODY){ - char* barrier_end = memmem(buffer, blen, content.boundary->c, content.boundary->len); - if(barrier_end == NULL){ - str* temp = str_initl(content.current->c, content.current->len); - str_pushl(temp, buffer, blen); - barrier_end = memmem(temp->c, temp->len, content.boundary->c, content.boundary->len); - if(barrier_end != NULL) abort(); // todo - - str* temp2 = content.current; - content.current = temp; - str_free(temp2); - - } else { - char* start = barrier_end, *end = barrier_end; - for(; *start != '\n'; start--); - for(; *end != '\n'; end++); - int clen = start - buffer; - str_pushl(content.current, buffer, clen); - luaI_tsetsl(L, rfiles_idx, "content", content.current->c, content.current->len - 1); - str_clear(content.current); - blen-= end - buffer; - buffer = end; - content.status = BARRIER_READ; - goto file_start; - } - - } + if(content.status == BARRIER_START){ + for(; blen > 0; buffer++, blen--){ + if(*buffer == '\n'){ + content.status = BARRIER_END; + blen--; + buffer++; + break; + } + } + } + + if(content.status == BARRIER_END){ + int check = 80; + if(content.current->len < check) check = content.current->len; + ssize_t backtrack = content.current->len - check; + + str_pushl(content.current, buffer, blen); + char* end = memmem(content.current->c + backtrack, content.current->len - backtrack, content.boundary->c, content.boundary->len); + + if(end != NULL){ + ssize_t size = content.current->len - (end - content.current->c + 4); + str_popb(content.current, content.current->len - (end - content.current->c) + 4); + size_t header_len = (char*)memmem(content.current->c, content.current->len, "\r\n\r\n", 4) - content.current->c; + + parray_t* header = parray_init(); + parse_header_kv(content.current->c, header_len, header); + + str* cd = (str*)parray_get(header, "content-disposition"); + if(cd != NULL){ + lua_newtable(L); + int newfile_idx = lua_gettop(L); + + parray_t* cd_parse = parray_init(); + gen_parse(cd->c, cd->len, &cd_parse); + lua_newtable(L); + int cdidx = lua_gettop(L); + luaI_fromparray(L, cdidx, cd_parse, 1); + + luaI_fromparray(L, newfile_idx, header, 1); + luaI_tsetv(L, newfile_idx, "content-disposition", cdidx); + + str* name = (str*)parray_get(cd_parse, "name"); + if(name == NULL) name = (str*)parray_get(cd_parse, "filename"); + + if(name == NULL){ + int ind = lua_objlen(L, *files_idx) + 1; + lua_pushinteger(L, ind); + lua_pushvalue(L, newfile_idx); + lua_settable(L, *files_idx); + } + else { + luaI_tsetv(L, *files_idx, name->c, newfile_idx); + } + parray_clear(cd_parse, STR); + + lua_pushlstring(L, content.current->c + header_len + 4, content.current->len - header_len - 4); + lua_setfield(L, newfile_idx, "body"); + } + + str_clear(content.current); + parray_clear(header, STR); + content.status = BARRIER_START; + + ssize_t oblen = blen; + blen = oblen - (oblen - size); + buffer += oblen - blen; + goto file_start; + } + } } *_content = content; diff --git a/src/net/util.c b/src/net/util.c index ce4fc26..08a9a55 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -46,41 +46,43 @@ void lowercase(char* c, uint64_t len){ * @brief converts the request buffer into a parray_t * */ -int parse_header(char* buffer, int header_eof, parray_t** _table){ - if(header_eof == -1) return -1; - - parray_t* table = parray_init(); +ssize_t parse_header_head(char* buffer, size_t header_len, parray_t* table){ str* current = str_init(""); - int oi = 0; + int i = 0; int item = 0; - for(; oi != header_eof; oi++){ - if(buffer[oi] == ' ' || buffer[oi] == '\n'){ - if(buffer[oi] == '\n') current->c[current->len - 1] = 0; + for(; i != header_len; i++){ + if(buffer[i] == ' ' || buffer[i] == '\n'){ + if(buffer[i] == '\n') current->c[current->len - 1] = 0; if(item < 3) parray_set(table, item == 0 ? "request" : item == 1 ? "path" : "version", (void*)str_init(current->c)); str_clear(current); item++; - if(buffer[oi] == '\n') break; + if(buffer[i] == '\n') break; } else { - if(oi >= max_uri_len){ - *_table = table; + if(i >= max_uri_len){ str_free(current); return -2; } - str_pushl(current, buffer + oi, 1); + str_pushl(current, buffer + i, 1); } } + str_free(current); + if(item < 3){ - str_free(current); - *_table = table; return -1; } - int key = 1; + return i; +} + +int parse_header_kv(char* buffer, size_t header_len, parray_t* table){ + str* current = str_init(""); str* sw = NULL; - for(int i = oi + 1; i != header_eof; i++){ + int key = 1; + + for(int i = 0; i != header_len; i++){ if(buffer[i] == ' ' && strcmp(current->c, "") == 0) continue; if((key && buffer[i] == ':') || (!key && buffer[i] == '\n')){ if(key){ @@ -88,7 +90,7 @@ int parse_header(char* buffer, int header_eof, parray_t** _table){ current = str_init(""); key = 0; } else { - if(buffer[oi] == '\n') current->c[current->len - 1] = 0; + current->c[current->len - 1] = 0; //duplicate keys would cause memory leaks, ignore them for now //todo: figure out system to handle this str* id = (str*)parray_get(table, sw->c); @@ -103,16 +105,30 @@ int parse_header(char* buffer, int header_eof, parray_t** _table){ continue; } else str_pushc(current, buffer[i]); } + if(sw != NULL){ + lowercase(sw->c, sw->len); parray_set(table, sw->c, (void*)str_init(current->c)); str_free(sw); } - str_free(current); + + return 0; +} + +int parse_header(char* buffer, size_t header_len, parray_t** _table){ + if(header_len == -1) return -1; + parray_t* table = parray_init(); + + ssize_t used = parse_header_head(buffer, header_len, table); + if(used == -1) return -1; + + parse_header_kv(buffer + used + 1, header_len - used, table); *_table = table; return 0; } + /** * @brief contructs an http request * diff --git a/src/net/util.h b/src/net/util.h index 602ee53..34bf317 100644 --- a/src/net/util.h +++ b/src/net/util.h @@ -22,7 +22,10 @@ int64_t recv_header(struct net_data* ctx, char** _buffer, char** header_eof); * @param {parray_t**} pointer to a unallocated parray_t * @return {int} returns 0 or -1 on failure */ -int parse_header(char* buffer, int header_eof, parray_t** _table); +int parse_header(char* buffer, size_t header_len, parray_t** _table); +ssize_t parse_header_head(char* buffer, size_t header_len, parray_t* table); +int parse_header_kv(char* buffer, size_t header_len, parray_t* table); + /** * @brief contructs an http request diff --git a/src/net/websocket.c b/src/net/websocket.c index 06283f6..0f6081f 100644 --- a/src/net/websocket.c +++ b/src/net/websocket.c @@ -212,7 +212,7 @@ int l_websocket_upgrade(lua_State* L){ data->ctx = ctx->ctx; data->buffer = str_init(""); - luaI_tsetnil(L, req_idx, "roll"); + luaI_tsetnil(L, req_idx, "load"); luaI_tsetlud(L, res_idx, "_ws", data); #warning "missing ws commands" luaI_tsetcf(L, res_idx, "send", l_ws_write); diff --git a/src/types/str.c b/src/types/str.c index b4c0b5e..5f47db1 100644 --- a/src/types/str.c +++ b/src/types/str.c @@ -38,6 +38,15 @@ void str_free(str* s){ free(s);
}
+void str_loadatleast(str* s, size_t bytes){
+ if(s->_bytes < bytes)
+ s->c = realloc(s->c, s->_bytes = bytes);
+}
+
+void str_loadex(str* s, size_t bytes){
+ s->c = realloc(s->c, s->_bytes = s->len + 1 + bytes);
+}
+
void str_push(str* s, const char* insert){
s->len += strlen(insert);
if(s->len + 1 >= s->_bytes)
diff --git a/src/types/str.h b/src/types/str.h index 131454c..59ea009 100644 --- a/src/types/str.h +++ b/src/types/str.h @@ -23,4 +23,6 @@ void str_pushc(str*, char); void str_clear(str*); void str_popf(str*, int); void str_popb(str*, int); +void str_loadatleast(str* s, size_t bytes); +void str_loadex(str* s, size_t bytes); #endif //__STR_H @@ -13,7 +13,7 @@ multipart/form-data = (null)
boundary = awa
*/
-int gen_parse(char* inp, int len, parray_t** _table){
+int gen_parse(char* inp, ssize_t len, parray_t** _table){
str* current = str_init(""), *last = NULL;
int state = 0;
@@ -32,7 +32,7 @@ clock_t _end##name = clock();\ printf("%s took %f\n",desc, (double)(_end##name - _begin##name) / CLOCKS_PER_SEC); -int gen_parse(char*,int, parray_t**); +int gen_parse(char*,ssize_t, parray_t**); int tolower(int i); void str_lowercase(str* str); diff --git a/tests/old/net2.lua b/tests/old/net2.lua index bb69051..2398b63 100644 --- a/tests/old/net2.lua +++ b/tests/old/net2.lua @@ -1,8 +1,7 @@ ---(this is in tests/net2.lua) +--(this is in tests/old/net2.lua) net = require "lullaby.net" local crypto = require "lullaby.crypto" local port = 8080 -MAX_LENGTH = 2048 net.listen(function(server) @@ -10,8 +9,8 @@ net.listen(function(server) server:POST("/", function(res, req) --creates a sha0 hash object local hash = crypto.sha0() - --loads an extra 2048 characters from the request body (the body is not guaranteed to be >= 2048 characters, reasoning in docs) - req:roll(MAX_LENGTH) + + req:load() --incremental hashes allow updating via addition, in this case adding the body and getting a string from it hash = (hash + req.Body):final() @@ -21,4 +20,3 @@ net.listen(function(server) end) end, port) - |
