commit ff76d854fc286e683a7ec5d16ac24fb03f232941
parent 81a6480a4fdcbfd7a9da57a7b55e6a69c7779015
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 28 Aug 2024 01:37:02 +0100
extend libfetch lua glue to other HTTP methods
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/pkgs/fetch-freebsd/lua-glue.c b/pkgs/fetch-freebsd/lua-glue.c
@@ -57,8 +57,38 @@ int lp_fetch(lua_State *L) {
return lp_fetched(L, fp, &stat);
}
+int lp_request(lua_State *L) {
+ const char * request_method = luaL_checkstring(L, 1);
+ const char * url_string = luaL_checkstring(L, 2);
+ const char * flags = luaL_optstring(L, 3, "");
+ time_t if_modified_since = luaL_optinteger(L, 4, 0);
+ const char * content_type = lua_tostring(L, 5);
+ const char * body = lua_tostring(L, 6);
+
+ struct url *url = fetchParseURL(url_string);
+ if(url == NULL) {
+ return lp_error(L, -1, "url not parseable");
+ }
+ url->ims_time = if_modified_since;
+ struct url_stat stat;
+
+ FXRETTYPE fp = http_request_body(url,
+ request_method,
+ &stat,
+ NULL, /* no proxy */
+ flags,
+ content_type,
+ body);
+ fetchFreeURL(url);
+ if(fp == NULL) {
+ return lp_error(L, fetchLastErrCode, fetchLastErrString);
+ }
+ return lp_fetched(L, fp, &stat);
+}
+
static const struct luaL_Reg funcs [] = {
{"fetch", lp_fetch},
+ {"request", lp_request},
{NULL, NULL} /* sentinel */
};