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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d7c8a7236299d04d8b414435631a7e8c166580b
4
- data.tar.gz: a091fdb0bb8573b040baae2f0b58265bfb1c1349
3
+ metadata.gz: 681df740040b4efceff281b94ad161ca37be4819
4
+ data.tar.gz: de47b720014006d07a4d84d9bc178032f76c03f8
5
5
  SHA512:
6
- metadata.gz: 660597e1a9c2cf47a9fe57545ac30e126b028c6f1012e90207b2346cdd67a347d2dee4a9f0443af34d82d75c163a33ee1f6f29a5911918680af008c0e00c9fb9
7
- data.tar.gz: fbe5c0eda83ea7b74bc8123e6812a845e6d55fe4a6a7fe2f96c8b9de533727555d68d0ae5c7e51299588443014e57ed3110d83c7587a732788d711af76568d63
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
- require 'escher/version'
6
- require 'escher/request/factory'
7
- require 'escher/auth'
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
@@ -341,9 +341,4 @@ module Escher
341
341
  end
342
342
 
343
343
  end
344
-
345
-
346
- class EscherError < RuntimeError
347
- end
348
-
349
344
  end
@@ -0,0 +1,2 @@
1
+ class Escher::EscherError < RuntimeError
2
+ end
@@ -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,3 @@
1
+ module Escher::Request::DCI
2
+ require 'escher/request/dci/rack_env'
3
+ end
@@ -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,9 +1,3 @@
1
- require 'escher/request/base'
2
- require 'escher/request/hash_request'
3
- require 'escher/request/rack_request'
4
- require 'escher/request/legacy_request'
5
- require 'escher/request/action_dispatch_request'
6
-
7
1
  module Escher
8
2
  module Request
9
3
  class Factory
@@ -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.select { |k, v| k =~ /^HTTP_/i }.map { |k, v| [k.sub(/^HTTP_/i, '').gsub('_', '-'), v] }
31
+ @headers ||= get_headers_by_rack_env(@rack_request.env)
30
32
  end
31
33
 
32
34
  def method
@@ -1,3 +1,3 @@
1
1
  module Escher
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -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.5
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-17 00:00:00.000000000 Z
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