Skip to content

Commit

Permalink
Merge pull request #32 from securenative/dev
Browse files Browse the repository at this point in the history
Support legacy header extraction
  • Loading branch information
inbaltako authored Oct 28, 2020
2 parents 1094b18 + a2328b6 commit a5dcfd0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
securenative (0.1.37)
securenative (0.1.38)

GEM
remote: https://rubygems.org/
Expand Down
9 changes: 8 additions & 1 deletion lib/securenative/frameworks/hanami.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ def self.get_method(request)
def self.get_headers(request)
begin
headers = {}
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|

request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}

if headers.length == 0
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}
end
return headers
rescue StandardError
nil
Expand Down
9 changes: 8 additions & 1 deletion lib/securenative/frameworks/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ def self.get_method(request)
def self.get_headers(request)
begin
headers = {}
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|

request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}

if headers.length == 0
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}
end
return headers
rescue StandardError
nil
Expand Down
9 changes: 8 additions & 1 deletion lib/securenative/frameworks/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ def self.get_method(request)
def self.get_headers(request)
begin
headers = {}
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|

request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}

if headers.length == 0
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
}
end
return headers
rescue StandardError
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/securenative/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SecureNative
VERSION = '0.1.37'
VERSION = '0.1.38'
end
2 changes: 1 addition & 1 deletion spec/securenative/spec_api_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'YOUR_API_KEY',
'Content-Type' => 'application/json',
'Sn-Version' => '0.1.37',
'Sn-Version' => '0.1.38',
'User-Agent' => 'SecureNative-ruby'
}
).to_return(status: 200, body: '', headers: {})
Expand Down
6 changes: 3 additions & 3 deletions spec/securenative/spec_event_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'YOUR_API_KEY',
'Content-Type' => 'application/json',
'Sn-Version' => '0.1.37',
'Sn-Version' => '0.1.38',
'User-Agent' => 'SecureNative-ruby'
})
.to_return(status: 200, body: '', headers: {})
Expand All @@ -53,7 +53,7 @@ def initialize
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'YOUR_API_KEY',
'Content-Type' => 'application/json',
'Sn-Version' => '0.1.37',
'Sn-Version' => '0.1.38',
'User-Agent' => 'SecureNative-ruby'
})
.to_return(status: 401, body: '', headers: {})
Expand All @@ -74,7 +74,7 @@ def initialize
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'YOUR_API_KEY',
'Content-Type' => 'application/json',
'Sn-Version' => '0.1.37',
'Sn-Version' => '0.1.38',
'User-Agent' => 'SecureNative-ruby'
})
.to_return(status: 500, body: '', headers: {})
Expand Down
2 changes: 1 addition & 1 deletion spec/securenative/spec_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'YOUR_API_KEY',
'Content-Type' => 'application/json',
'Sn-Version' => '0.1.37',
'Sn-Version' => '0.1.38',
'User-Agent' => 'SecureNative-ruby'
}).to_return(status: 200, body: '', headers: {})

Expand Down

0 comments on commit a5dcfd0

Please sign in to comment.