From 985f56768f6141509986b1c98cbed8b757e002bd Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 29 Aug 2013 18:58:08 +0200 Subject: [PATCH] follow Rack specifications for QUERY_STRING,SCRIPT_NAME,SERVER_NAME and SERVER_PORT --- plugins/rack/rack_plugin.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/rack/rack_plugin.c b/plugins/rack/rack_plugin.c index 9245eee3..d429f910 100644 --- a/plugins/rack/rack_plugin.c +++ b/plugins/rack/rack_plugin.c @@ -818,6 +818,18 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) { uwsgi_apps[wsgi_req->app_id].requests++; env = rb_hash_new(); + // the following vars have to always been defined (we skip REQUEST_METHOD and PATH_INFO as they should always be available) + rb_hash_aset(env, rb_str_new2("SCRIPT_NAME"), rb_str_new2("")); + rb_hash_aset(env, rb_str_new2("QUERY_STRING"), rb_str_new2("")); + rb_hash_aset(env, rb_str_new2("SERVER_NAME"), rb_str_new2(uwsgi.hostname)); + // SERVER_PORT + char *server_port = strchr(wsgi_req->socket->name, ':'); + if (server_port) { + rb_hash_aset(env, rb_str_new2("SERVER_PORT"), rb_str_new(server_port+1, strlen(server_port+1))); + } + else { + rb_hash_aset(env, rb_str_new2("SERVER_PORT"), rb_str_new2("80")); + } // fill ruby hash for(i=0;ivar_cnt;i++) {