From 9cc83982de88e1643a947113300395d313754b7f Mon Sep 17 00:00:00 2001 From: Ezra Jennings Date: Fri, 31 Aug 2018 19:59:38 -0400 Subject: [PATCH] fix forwarding of headers starting with http_ in the proxy (#12) --- .gitignore | 1 + CHANGELOG.md | 3 +++ lib/mauth/proxy.rb | 4 ++-- lib/mauth/version.rb | 2 +- mauth-client.gemspec | 1 + spec/proxy_spec.rb | 15 +++++++++++++++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 28b398a..b608833 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .bundle .yardoc +/config /coverage /yardoc /log diff --git a/CHANGELOG.md b/CHANGELOG.md index df1d137..c15a97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # MAuth-Client History +## v4.0.4 +- Restore original behavior in the proxy of forwarding of headers that begin with HTTP_ (except for HTTP_HOST) but removing the HTTP_. + ## v4.0.3 - Updated signature to decode number sign (#) in requests diff --git a/lib/mauth/proxy.rb b/lib/mauth/proxy.rb index 985b34b..3711f12 100644 --- a/lib/mauth/proxy.rb +++ b/lib/mauth/proxy.rb @@ -55,8 +55,8 @@ def call(request_env) request_env['rack.input'].rewind request_headers = {} request_env.each do |k, v| - if k.start_with?('HTTP_') && !%w(HTTP_HOST).include?(k) - name = $' + if k.start_with?('HTTP_') && k != 'HTTP_HOST' + name = k.sub(/\AHTTP_/, '') request_headers[name] = v end end diff --git a/lib/mauth/version.rb b/lib/mauth/version.rb index dbd6780..f62aa89 100644 --- a/lib/mauth/version.rb +++ b/lib/mauth/version.rb @@ -1,3 +1,3 @@ module MAuth - VERSION = '4.0.3'.freeze + VERSION = '4.0.4'.freeze end diff --git a/mauth-client.gemspec b/mauth-client.gemspec index 8f91fb1..53af19e 100644 --- a/mauth-client.gemspec +++ b/mauth-client.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'dice_bag', '>= 0.9', '< 2.0' spec.add_development_dependency 'bundler', '~> 1.10' + spec.add_development_dependency 'byebug' spec.add_development_dependency 'kender', '~> 0.4' spec.add_development_dependency 'rack-test', '~> 0.6.3' spec.add_development_dependency 'rake', '~> 10.0' diff --git a/spec/proxy_spec.rb b/spec/proxy_spec.rb index 38efe7c..6cf75b9 100644 --- a/spec/proxy_spec.rb +++ b/spec/proxy_spec.rb @@ -54,5 +54,20 @@ def run_request(request_method, request_fullpath, request_body, request_headers) mp.call(env) expect(double.headers["Expiry-time"]).to eq("3/6/1981 12:01.00") end + + it 'forwards headers that begin with HTTP_ except for HTTP_HOST and removes the HTTP_ prefix' do + double = FakeConnection.new + allow(Faraday).to receive(:new).and_return(double) + mp = MAuth::Proxy.new(url) + http_headers = { 'HTTP_FOO' => 'bar_value', 'HTTP_HOST' => 'my_host', 'HTTP_BIZ' => 'buzz_value' } + mp.call(Rack::MockRequest.env_for(url, http_headers)) + expect(double.headers['FOO']).to eq('bar_value') + expect(double.headers['BIZ']).to eq('buzz_value') + expect(double.headers.keys).to_not include('HTTP_HOST') + expect(double.headers.keys).to_not include('HOST') + expect(double.headers.keys).to_not include('HTTP_FOO') + expect(double.headers.keys).to_not include('HTTP_BIZ') + end + end end