You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/09/12 09:35:35 UTC

[6/7] git commit: Core: Make MatrixParams not overide PATH_INFO

Core: Make MatrixParams not overide PATH_INFO

* Overiding PATH_INFO with REQUEST_URI cause incorrect
  incorrect mapping of application.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/6d1be0aa
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/6d1be0aa
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/6d1be0aa

Branch: refs/heads/master
Commit: 6d1be0aa60250b15a90a11fe550ba911601ef728
Parents: 77f879a
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu Sep 6 14:14:15 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue Sep 11 12:08:27 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/core_ext/string.rb |    4 ++++
 server/lib/sinatra/rack_matrix_params.rb |   20 +++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6d1be0aa/server/lib/deltacloud/core_ext/string.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
index bc382ed..483fe33 100644
--- a/server/lib/deltacloud/core_ext/string.rb
+++ b/server/lib/deltacloud/core_ext/string.rb
@@ -73,6 +73,10 @@ class String
     "#{self[0..(length/2)]}#{end_string}"
   end
 
+  def remove_matrix_params
+    self.gsub(/;([^\/]*)/, '').gsub(/\?(.*)$/, '')
+  end
+
   unless "".respond_to? :each
     alias :each :each_line
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6d1be0aa/server/lib/sinatra/rack_matrix_params.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/rack_matrix_params.rb b/server/lib/sinatra/rack_matrix_params.rb
index e999f89..8a489d3 100644
--- a/server/lib/sinatra/rack_matrix_params.rb
+++ b/server/lib/sinatra/rack_matrix_params.rb
@@ -36,15 +36,21 @@ module Rack
     #
     # All HTTP methods are supported, in case of POST they will be passed as a
     # regular <form> parameters.
-
     def call(env)
-      # Copy PATH_INFO to REQUEST_URI if Rack::Test
-      env['REQUEST_URI'] = env['PATH_INFO'] if env['rack.test']
-      env['REQUEST_PATH'] = env['PATH_INFO'] if env['rack.test']
+
+      # This ugly hack should fix the issue with Rack::Test where
+      # these two variables are empty and Rack::Test will always
+      # return 404.
+      #
+      if env['rack.test']
+        env['REQUEST_URI'] = env['PATH_INFO']
+        env['REQUEST_PATH'] = env['PATH_INFO']
+      end
 
       # Split URI to components and then extract ;var=value pairs
-      uri_components = env['REQUEST_URI'].split('/')
       matrix_params = {}
+      uri_components = (env['rack.test'] ? env['PATH_INFO'] : env['REQUEST_URI']).split('/')
+
       uri_components.each do |component|
         sub_components, value = component.split(/\;(\w+)\=/), nil
         next unless sub_components.first  # Skip subcomponent if it's empty (usually /)
@@ -80,8 +86,8 @@ module Rack
 
       # This is needed for OpenShift deployment / Passenger
       if env['REQUEST_PATH']
-        env['REQUEST_PATH'] = env['REQUEST_PATH'].gsub(/;([^\/]*)/, '').gsub(/\?(.*)$/, '')
-        env['PATH_INFO'] = env['REQUEST_PATH']
+        env['REQUEST_PATH'] = env['REQUEST_PATH'].remove_matrix_params
+        env['PATH_INFO'] = env['PATH_INFO'].remove_matrix_params
       end
 
       # (2) Append the matrix params to the 'normal' request params