~panda-roux/MoonGem

13664c3974a62feebfdc7ae6be0d15bde1864785 — panda-roux 6 months ago 20b0588
adding mg.set_mimetype
3 files changed, 18 insertions(+), 0 deletions(-)

M README.md
M src/api.c
M src/script.c
M README.md => README.md +2 -0
@@ 128,6 128,8 @@ If a method is called which modifies the response's status code (which all but t

- `mg.set_language(<language>)`
    - Sets the `lang` portion of the response header, indicating the language(s) that the page is written in
- `mg.set_mimetype(<mimetype>)`
    - Sets the response mimetype string, indicating the type of content being delivered.  The default for gemtext documents is `text/gemini; charset=utf-8`.
- `mg.success()`
    - Sets the response status code to 20 (OK)
    - Only really useful in pre- and post-request scripts

M src/api.c => src/api.c +13 -0
@@ 68,6 68,19 @@ int api_set_lang(lua_State* L) {
  return 0;
}

int api_set_mimetype(lua_State* L) {
  lua_settop(L, 1);

  const char* mimetype = luaL_checkstring(L, 1);

  lua_getfield(L, LUA_REGISTRYINDEX, FLD_RESPONSE);
  response_t* response = (response_t*)lua_touserdata(L, -1);

  set_response_mime(response, mimetype);

  return 0;
}

int api_get_input(lua_State* L) {
  lua_settop(L, 1);


M src/script.c => src/script.c +3 -0
@@ 26,6 26,7 @@
#define FUNC_HAS_CERT "has_cert"

#define FUNC_LANG "set_language"
#define FUNC_MIMETYPE "set_mimetype"
#define FUNC_SUCCESS "success"
#define FUNC_TEMP_REDIRECT "temp_redirect"
#define FUNC_REDIRECT "redirect"


@@ 78,6 79,7 @@ int api_has_cert(lua_State* L);

/* Response */
int api_set_lang(lua_State* L);
int api_set_mimetype(lua_State* L);
int api_success(lua_State* L);
int api_temp_redirect(lua_State* L);
int api_perm_redirect(lua_State* L);


@@ 118,6 120,7 @@ static void set_api_methods(lua_State* L) {
                        {FUNC_HAS_CERT, api_has_cert},

                        {FUNC_LANG, api_set_lang},
                        {FUNC_MIMETYPE, api_set_mimetype},
                        {FUNC_REDIRECT, api_perm_redirect},
                        {FUNC_SUCCESS, api_success},
                        {FUNC_TEMP_REDIRECT, api_temp_redirect},