Bug #1308

lighty.env['request.method'] and lighty.env['request.protocol'] always return nil

Added by Anonymous over 6 years ago. Updated about 6 years ago.

Status:FixedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:mod_magnet
Target version:1.4.20
Missing in 1.5.x:

Description

magnet_env_get_buffer doesn't implement request.method nor request.protocol, thus always returning a nil value.

Both are merely skipped in magnet_env_get_buffer() :


switch (env[i].type) {
case MAGNET_ENV_REQUEST_METHOD:   break;
case MAGNET_ENV_REQUEST_PROTOCOL:   break;
}

History

#1 Updated by Anonymous over 6 years ago

Here's a patch against 1.4.16, that adds the two missing table entries.

As both values are stored as integer in the request struct, I added an argument "needs_free" to the magnet_env_get_buffer() function, which indicates that the returned buffer has to be free'd. An alternative approach would be to store the two fields in the request structure, but this one is less intrusive.


--- lighttpd-1.4.16.orig/src/mod_magnet.c       2007-08-20 17:51:05.620274276 +0200
+++ lighttpd-1.4.16/src/mod_magnet.c    2007-08-20 17:54:03.864690610 +0200
@@ -369,7 +369,7 @@
                } type;
 } magnet_env_t;

-static buffer *magnet_env_get_buffer(server *srv, connection *con, const char *key) {
+static buffer *magnet_env_get_buffer(server *srv, connection *con, const char *key, int* needs_free) {
        buffer *dest = NULL;
        size_t i;

@@ -414,10 +414,10 @@
        case MAGNET_ENV_URI_AUTHORITY: dest = con->uri.authority; break;
        case MAGNET_ENV_URI_QUERY: dest = con->uri.query; break;

-       case MAGNET_ENV_REQUEST_METHOD:   break;
+       case MAGNET_ENV_REQUEST_METHOD:   dest = buffer_init_string(get_http_method_name(con->request.http_method)); *needs_free = 1; break;
        case MAGNET_ENV_REQUEST_URI:      dest = con->request.uri; break;
        case MAGNET_ENV_REQUEST_ORIG_URI: dest = con->request.orig_uri; break;
-       case MAGNET_ENV_REQUEST_PROTOCOL: break;
+       case MAGNET_ENV_REQUEST_PROTOCOL: dest = buffer_init_string(get_http_version_name(con->request.http_version)); *needs_free = 1; break;

        case MAGNET_ENV_UNSET: break;
        }
@@ -431,6 +431,7 @@

        const char *key = luaL_checkstring(L, 2);
        buffer *dest = NULL;
+       int needs_free = 0;

        lua_pushstring(L, "lighty.srv");
        lua_gettable(L, LUA_REGISTRYINDEX);
@@ -442,7 +443,7 @@
        con = lua_touserdata(L, -1);
        lua_pop(L, 1);

-       dest = magnet_env_get_buffer(srv, con, key);
+       dest = magnet_env_get_buffer(srv, con, key, &needs_free);

        if (dest && dest->used) {
                lua_pushlstring(L, dest->ptr, dest->used - 1);
@@ -450,6 +451,8 @@
                lua_pushnil(L);
        }

+       if (needs_free) buffer_free(dest);
+
        return 1;
 }

@@ -460,6 +463,7 @@
        const char *key = luaL_checkstring(L, 2);
        const char *val = luaL_checkstring(L, 3);
        buffer *dest = NULL;
+       int needs_free = 0;

        lua_pushstring(L, "lighty.srv");
        lua_gettable(L, LUA_REGISTRYINDEX);
@@ -471,8 +475,9 @@
        con = lua_touserdata(L, -1);
        lua_pop(L, 1);

-       if (NULL != (dest = magnet_env_get_buffer(srv, con, key))) {
+       if (NULL != (dest = magnet_env_get_buffer(srv, con, key, &needs_free))) {
                buffer_copy_string(dest, val);
+               if (needs_free) buffer_free(dest);
        } else {
                /* couldn't save */

#2 Updated by Anonymous over 6 years ago

since we are talking about LUA which is very flexible.

Why not just return the request.request(or request.request_line) and let the lua script parse the method and version ?

As even though these 2 parameter are documented, they are not usable(i.e. no existing code is using them). So may be just drop them and have a new "request.request_line" ?

Just have to remember to disable the env set method as they should not be settable.

-- linux

#3 Updated by stbuehler about 6 years ago

  • Status changed from New to Fixed
  • Resolution set to fixed

Fixed in r2137

Also available in: Atom