Skip to content

Commit

Permalink
fix forwarding of headers starting with http_ in the proxy (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejennings-mdsol authored and jfeltesse-mdsol committed Aug 31, 2018
1 parent 766ab8f commit 9cc8398
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.bundle
.yardoc

/config
/coverage
/yardoc
/log
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/mauth/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mauth/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MAuth
VERSION = '4.0.3'.freeze
VERSION = '4.0.4'.freeze
end
1 change: 1 addition & 0 deletions mauth-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions spec/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9cc8398

Please sign in to comment.