yko/ngx_mod_psgi — Issue #2: little bit of refactoring and thoughts about the future
Author: zzzcpan
Created: 2011-12-13 02:10:06+00:00
State: open

Hi. Recently I was looking into your module and have couple of suggestions that may help a bit in the future (or not).
Actually, I'm more interested in merging your module with my distribution than anything else. I think it would benefit everyone.

So it would be nice to have everything restructured and put together into a single file so we can merge. As time permits of course. We can discuss this privately.

And other thing. I've noticed you aren't using internal variables for PSGI ENV. It can help a bit to make things less complex and less dependent on internals in the future. Basically you can just map every internal variable into PSGI ENV.

Here's a simple example on using variables (you probably can take it out of nginx.xs, but just in case; and don't take it as something important, it isn't):

HV *hv;
ngx_str_t var;
ngx_http_variable_value_t *vv;
ngx_uint_t hash;
...

hv = newHV (); /* PSGI ENV */
...

hash = ngx_hash_key ((u_char *) "scheme", sizeof ("scheme") - 1);

var.len = sizeof ("scheme") - 1;
var.data = (u_char *) "scheme";

vv = ngx_http_get_variable(r, &var, hash);

if (vv != NULL && !vv->not_found) {

hv_store (hv, "psgi.url_scheme", sizeof("psgi.url_scheme") - 1,
newSVpvn ((char *) vv->data, vv->len), 0);
}