escher 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/escher.rb +8 -3
- data/lib/escher/auth.rb +0 -5
- data/lib/escher/escher_error.rb +2 -0
- data/lib/escher/request.rb +13 -0
- data/lib/escher/request/action_dispatch_request.rb +3 -3
- data/lib/escher/request/dci.rb +3 -0
- data/lib/escher/request/dci/rack_env.rb +27 -0
- data/lib/escher/request/factory.rb +0 -6
- data/lib/escher/request/rack_request.rb +3 -1
- data/lib/escher/version.rb +1 -1
- data/spec/escher/request/action_dispatch_request_spec.rb +6 -0
- data/spec/escher/request/rack_request_spec.rb +7 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 681df740040b4efceff281b94ad161ca37be4819
|
4
|
+
data.tar.gz: de47b720014006d07a4d84d9bc178032f76c03f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bcbd87cde7db30cc2aee5ed5f230890d08aefa8ad1274cd63fcf2bafe99130f3806ca71f939accb69b2a9b6677eda37790d4e50b6e56f9e6e3973da726d83ed
|
7
|
+
data.tar.gz: e894f5ffb2c9611ec221e10d1347dae7aba8746266359aad18a98258786601f3aaeda9570fee1eb161fa107a84d2833329199c62a6d03199d9195fe707e9306d
|
data/lib/escher.rb
CHANGED
@@ -2,6 +2,11 @@ require 'addressable/uri'
|
|
2
2
|
require 'time'
|
3
3
|
require 'openssl'
|
4
4
|
|
5
|
-
|
6
|
-
require 'escher/
|
7
|
-
|
5
|
+
module Escher
|
6
|
+
require 'escher/version'
|
7
|
+
|
8
|
+
require 'escher/auth'
|
9
|
+
require 'escher/request'
|
10
|
+
require 'escher/escher_error'
|
11
|
+
|
12
|
+
end
|
data/lib/escher/auth.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Escher::Request
|
2
|
+
|
3
|
+
require 'escher/request/dci'
|
4
|
+
|
5
|
+
require 'escher/request/base'
|
6
|
+
require 'escher/request/hash_request'
|
7
|
+
require 'escher/request/rack_request'
|
8
|
+
require 'escher/request/legacy_request'
|
9
|
+
require 'escher/request/action_dispatch_request'
|
10
|
+
|
11
|
+
require 'escher/request/factory'
|
12
|
+
|
13
|
+
end
|
@@ -2,10 +2,10 @@ module Escher
|
|
2
2
|
module Request
|
3
3
|
class ActionDispatchRequest < Base
|
4
4
|
|
5
|
+
include Escher::Request::DCI::RackEnv
|
6
|
+
|
5
7
|
def headers
|
6
|
-
request.env
|
7
|
-
select { |header_name, _| header_name.start_with? "HTTP_" }.
|
8
|
-
map { |header_name, value| [header_name[5..-1].tr('_', '-'), value] }
|
8
|
+
get_headers_by_rack_env(request.env)
|
9
9
|
end
|
10
10
|
|
11
11
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Escher::Request::DCI::RackEnv
|
2
|
+
|
3
|
+
CUSTOM_HTTP_HEADER_MATCHER = /^HTTP_/
|
4
|
+
CONSTANT_HTTP_HEADER_KEYS = %w[CONTENT_LENGTH CONTENT_TYPE]
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def get_headers_by_rack_env(env)
|
9
|
+
format_headers(get_custom_http_headers(env) + get_constant_http_headers(env))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_custom_http_headers(env)
|
15
|
+
env.select { |env_str_key, _| env_str_key =~ CUSTOM_HTTP_HEADER_MATCHER }.to_a
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_constant_http_headers(env)
|
19
|
+
CONSTANT_HTTP_HEADER_KEYS.map { |env_key| [env_key, env[env_key]] }.select { |k, v| !v.nil? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def format_headers(array)
|
23
|
+
array.map { |header_name, value| [header_name.sub(CUSTOM_HTTP_HEADER_MATCHER, '').tr('_', '-'), value] }
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class Escher::Request::RackRequest < Escher::Request::Base
|
2
2
|
|
3
|
+
include Escher::Request::DCI::RackEnv
|
4
|
+
|
3
5
|
def initialize(request_env)
|
4
6
|
super(request_env)
|
5
7
|
@rack_request = request_env
|
@@ -26,7 +28,7 @@ class Escher::Request::RackRequest < Escher::Request::Base
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def headers
|
29
|
-
@headers ||= @rack_request.env
|
31
|
+
@headers ||= get_headers_by_rack_env(@rack_request.env)
|
30
32
|
end
|
31
33
|
|
32
34
|
def method
|
data/lib/escher/version.rb
CHANGED
@@ -29,6 +29,12 @@ describe Escher::Request::ActionDispatchRequest do
|
|
29
29
|
|
30
30
|
expect(subject.headers).to eq [['HOST-NAME', 'some host']]
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'should add the content-type and content-length to the headers' do
|
34
|
+
request_params.merge!( 'CONTENT_LENGTH' => '123', 'CONTENT_TYPE' => 'text/plain' )
|
35
|
+
|
36
|
+
expect(subject.headers).to eq [%w(CONTENT-LENGTH 123), %w(CONTENT-TYPE text/plain)]
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
|
@@ -31,6 +31,13 @@ describe Escher::Request::RackRequest do
|
|
31
31
|
|
32
32
|
expect(subject.headers).to eq [['HOST-NAME', 'some host']]
|
33
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
it 'should add the content-type and content-length to the headers' do
|
37
|
+
request_params.merge!( 'CONTENT_LENGTH' => '123', 'CONTENT_TYPE' => 'text/plain' )
|
38
|
+
|
39
|
+
expect(subject.headers).to eq [%w(CONTENT-LENGTH 123), %w(CONTENT-TYPE text/plain)]
|
40
|
+
end
|
34
41
|
end
|
35
42
|
|
36
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andras Barthazi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,8 +111,12 @@ files:
|
|
111
111
|
- escher.gemspec
|
112
112
|
- lib/escher.rb
|
113
113
|
- lib/escher/auth.rb
|
114
|
+
- lib/escher/escher_error.rb
|
115
|
+
- lib/escher/request.rb
|
114
116
|
- lib/escher/request/action_dispatch_request.rb
|
115
117
|
- lib/escher/request/base.rb
|
118
|
+
- lib/escher/request/dci.rb
|
119
|
+
- lib/escher/request/dci/rack_env.rb
|
116
120
|
- lib/escher/request/factory.rb
|
117
121
|
- lib/escher/request/hash_request.rb
|
118
122
|
- lib/escher/request/legacy_request.rb
|