Internal servlet attributes aren't always accessible
Closed this issue · 1 comments
I'm currently working to integrate a jruby/rails 3 app with Shibboleth, and I ran into an issue where I couldn't access the environment variables Apache was sending to the container (in my case tomcat7/trinidad).
I tracked it down to the way Rack::Handler::Servlet::DefaultEnv exposes those properties.
According to this: http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/connector/Request.html#getAttributeNames%28%29 some attribute names may not be returned from the java request.getAttributeNames.
There's no logic to specifically check for attributes not returned from getAttributeNames. In my case, the following patch fixed the problem for me, though I'm not sure if it's the best approach:
module Rack
module Handler
class Servlet
class DefaultEnv
def load_variable(env, key)
return nil if @servlet_env.nil?
case key
when 'CONTENT_TYPE'
content_type = @servlet_env.getContentType
env[key] = content_type if content_type
when 'CONTENT_LENGTH'
content_length = @servlet_env.getContentLength
env[key] = content_length.to_s if content_length >= 0
when 'PATH_INFO' then env[key] = @servlet_env.getPathInfo
when 'QUERY_STRING' then env[key] = @servlet_env.getQueryString || ''
when 'REMOTE_ADDR' then env[key] = @servlet_env.getRemoteAddr || ''
when 'REMOTE_HOST' then env[key] = @servlet_env.getRemoteHost || ''
when 'REMOTE_USER' then env[key] = @servlet_env.getRemoteUser || ''
when 'REQUEST_METHOD' then env[key] = @servlet_env.getMethod || 'GET'
when 'REQUEST_URI' then env[key] = @servlet_env.getRequestURI
when 'SCRIPT_NAME' then env[key] = @servlet_env.getScriptName
when 'SERVER_NAME' then env[key] = @servlet_env.getServerName || ''
when 'SERVER_PORT' then env[key] = @servlet_env.getServerPort.to_s
when 'SERVER_SOFTWARE' then env[key] = rack_context.getServerInfo
else
hidden_attr = @servlet_env.getAttribute(key)
if hidden_attr
env[key] = hidden_attr
else
nil
end
end
end
end
end
end
end
Thanks,
Dan
Nice catch Dan, thank you ... will make sure this is fixed in 1.1.15 (should be out in a few weeks) ...