class Rack::Test::Session
def env_for(uri, env)
def env_for(uri, env) env = DEFAULT_ENV.merge(@env).merge!(env) env['HTTP_HOST'] ||= [uri.host, (uri.port if uri.port != uri.default_port)].compact.join(':') env['HTTPS'] = 'on' if URI::HTTPS === uri env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if env[:xhr] env['REQUEST_METHOD'] ||= env[:method] ? env[:method].to_s.upcase : 'GET' params = env.delete(:params) query_array = [uri.query] if env['REQUEST_METHOD'] == 'GET' # Treat params as query params if params append_query_params(query_array, params) end elsif !env.key?(:input) env['CONTENT_TYPE'] ||= 'application/x-www-form-urlencoded' params ||= {} multipart = env.has_key?(:multipart) ? env.delete(:multipart) : env['CONTENT_TYPE'].start_with?('multipart/') if params.is_a?(Hash) if !params.empty? && data = build_multipart(params, false, multipart) env[:input] = data env['CONTENT_LENGTH'] ||= data.length.to_s env['CONTENT_TYPE'] = "#{multipart_content_type(env)}; boundary=#{MULTIPART_BOUNDARY}" else env[:input] = build_nested_query(params) end else env[:input] = params end end if query_params = env.delete(:query_params) append_query_params(query_array, query_params) end query_array.compact! query_array.reject!(&:empty?) uri.query = query_array.join('&') set_cookie(env.delete(:cookie), uri) if env.key?(:cookie) Rack::MockRequest.env_for(uri.to_s, env) end