rack-app 2.2.0 → 2.3.0

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: c3304681bebb6b2cf1f17d467c56de917705dcef
4
- data.tar.gz: b1ce48173f17fad8673d9ade0f62c155e3db230b
3
+ metadata.gz: a4fd38db32ac4c1f0c5cf3508fe5c6334d821e17
4
+ data.tar.gz: c80bad21912abd9d75f001dd5c852ce5d56cbd79
5
5
  SHA512:
6
- metadata.gz: e3c61fe0d4bd45eb0e430e1eb20ca0d5792994246a5bfe7089d443495f2be79506b3543a7627c50151203728b6e0e1e88b09118bb515cc8de9329edaca9f180e
7
- data.tar.gz: d05b9441214071df709ada06ae70f42397911db5071a95a7f583a3934131c47bda92fa03c537dd4733fca62038eb469bba82a00d720338c348026c786c0cee13
6
+ metadata.gz: 060ec6750c13c76716e5e4dd9cf7102aef908b35bd7fd2674b54739ccd68b0020deb04cc83de2c3df80596cd401fac1b4a0c35895201eb3a7777f9cae0fa1bba
7
+ data.tar.gz: 10eded51b03e212224e094cc95856c63b03ac0a5df994f285142e870adfb55de05d88c4a6a81cf6da54a1cabc08db22f40ff83f76500209ba273d1adc9a70269
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
@@ -2,8 +2,9 @@ module Rack::App::InstanceMethods::Upload
2
2
 
3
3
  def serve_file(file_path)
4
4
  raw_rack_resp = Rack::App::FileServer.serve_file(request.env, file_path)
5
+ response.status = raw_rack_resp[0]
5
6
  response.headers.merge!(raw_rack_resp[1])
6
- response.body = raw_rack_resp.last
7
+ response.body = raw_rack_resp[2]
7
8
  return nil
8
9
  end
9
10
 
data/lib/rack/app/test.rb CHANGED
@@ -2,6 +2,8 @@ require 'uri'
2
2
  require 'rack/app'
3
3
  module Rack::App::Test
4
4
 
5
+ require 'rack/app/test/utils'
6
+
5
7
  def self.included(klass)
6
8
  klass.__send__(:extend,SpecHelpers)
7
9
  end
@@ -40,109 +42,16 @@ module Rack::App::Test
40
42
  define_method(request_method) do |properties|
41
43
  properties ||= Hash.new
42
44
  url = properties.delete(:url)
43
- request_env = request_env_by(request_method, url, properties)
44
- rack_app.call(request_env).last
45
- end
46
- end
47
-
48
- def format_properties(properties)
49
- raise('use hash format such as params: {"key" => "value"} or headers with the same concept') unless properties.is_a?(Hash)
50
- properties[:params] ||= {}
51
- properties[:headers]||= {}
52
-
53
- properties
54
- end
55
-
56
- def request_env_by(request_method, url, raw_properties)
57
-
58
- properties = format_properties(raw_properties)
59
- additional_headers = properties[:headers].reduce({}) { |m, (k, v)| m.merge("HTTP_#{k.to_s.gsub('-', '_').upcase}" => v.to_s) }
60
-
61
-
62
- payload = raw_properties.delete(:payload)
63
-
64
- io = case payload
65
-
66
- when IO
67
- payload
45
+ request_env = Rack::App::Test::Utils.request_env_by(request_method, url, properties)
46
+ raw_response = rack_app.call(request_env)
68
47
 
69
- when String
70
- StringIO.new(payload.to_s)
71
-
72
- else
73
- StringIO.new('')
74
-
75
- end
76
-
77
- additional_headers["rack.input"]= ::Rack::Lint::InputWrapper.new(io)
78
-
79
- {
80
- "REMOTE_ADDR" => "192.168.56.1",
81
- "REQUEST_METHOD" => request_method.to_s.upcase,
82
- "REQUEST_PATH" => url,
83
- "REQUEST_URI" => url,
84
- "PATH_INFO" => url,
85
- "SERVER_PROTOCOL" => "HTTP/1.1",
86
- "CONTENT_LENGTH" => "0",
87
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
88
- "SERVER_NAME" => "hds-dev.ett.local",
89
- "SERVER_PORT" => "80",
90
- "QUERY_STRING" => encode_www_form(properties[:params].to_a),
91
- "HTTP_VERSION" => "HTTP/1.1",
92
- "HTTP_USER_AGENT" => "spec",
93
- "HTTP_HOST" => "spec.local",
94
- "HTTP_ACCEPT_ENCODING" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
95
- "HTTP_ACCEPT" => "*/*",
96
- "HTTP_CONNECTION" => "close"
97
- }.merge(additional_headers)
98
-
99
- end
100
-
101
- def encode_www_form(enum)
102
- enum.map do |k, v|
103
- if v.nil?
104
- encode_www_form_component(k)
105
- elsif v.respond_to?(:to_ary)
106
- v.to_ary.map do |w|
107
- str = encode_www_form_component(k)
108
- unless w.nil?
109
- str << '='
110
- str << encode_www_form_component(w)
111
- end
112
- end.join('&')
113
- else
114
- str = encode_www_form_component(k)
115
- str << '='
116
- str << encode_www_form_component(v)
48
+ body = []
49
+ raw_response[2].each do |e|
50
+ body << e
117
51
  end
118
- end.join('&')
119
- end
120
-
121
- TBLENCWWWCOMP_ = {} # :nodoc:
122
- 256.times do |i|
123
- TBLENCWWWCOMP_['%%%02X' % i] = i.chr
124
- end
125
- TBLENCWWWCOMP_[' '] = '+'
126
- TBLENCWWWCOMP_.freeze
127
- TBLDECWWWCOMP = {} # :nodoc:
128
- 256.times do |i|
129
- h, l = i>>4, i&15
130
- TBLDECWWWCOMP[i.chr]= '%%%X%X' % [h, l]
131
- TBLDECWWWCOMP[i.chr]= '%%%X%X' % [h, l]
132
- TBLDECWWWCOMP[i.chr]= '%%%x%X' % [h, l]
133
- TBLDECWWWCOMP[i.chr]= '%%%X%x' % [h, l]
134
- TBLDECWWWCOMP[i.chr]= '%%%x%x' % [h, l]
135
- end
136
- TBLDECWWWCOMP['+'] = ' '
137
- TBLDECWWWCOMP.freeze
138
-
139
- def encode_www_form_component(str)
140
- str = str.to_s.dup
141
52
 
142
- TBLENCWWWCOMP_.each do |from,to|
143
- str.gsub!(from,to)
53
+ return Rack::Response.new(body,raw_response[0],raw_response[1])
144
54
  end
145
- str
146
55
  end
147
56
 
148
57
  end
@@ -0,0 +1,103 @@
1
+ module Rack::App::Test::Utils
2
+ extend self
3
+
4
+ def format_properties(properties)
5
+ raise('use hash format such as params: {"key" => "value"} or headers with the same concept') unless properties.is_a?(Hash)
6
+ properties[:params] ||= {}
7
+ properties[:headers]||= {}
8
+
9
+ properties
10
+ end
11
+
12
+ def request_env_by(request_method, url, raw_properties)
13
+
14
+ properties = format_properties(raw_properties)
15
+ additional_headers = properties[:headers].reduce({}) { |m, (k, v)| m.merge("HTTP_#{k.to_s.gsub('-', '_').upcase}" => v.to_s) }
16
+
17
+ payload = raw_properties.delete(:payload)
18
+
19
+ io = case payload
20
+
21
+ when IO
22
+ payload
23
+
24
+ when String
25
+ StringIO.new(payload.to_s)
26
+
27
+ else
28
+ StringIO.new('')
29
+
30
+ end
31
+
32
+ additional_headers["rack.input"]= ::Rack::Lint::InputWrapper.new(io)
33
+
34
+ {
35
+ "REMOTE_ADDR" => "192.168.56.1",
36
+ "REQUEST_METHOD" => request_method.to_s.upcase,
37
+ "REQUEST_PATH" => url,
38
+ "REQUEST_URI" => url,
39
+ "PATH_INFO" => url,
40
+ "SERVER_PROTOCOL" => "HTTP/1.1",
41
+ "CONTENT_LENGTH" => "0",
42
+ "CONTENT_TYPE" => "application/x-www-form-urlencoded",
43
+ "SERVER_NAME" => "hds-dev.ett.local",
44
+ "SERVER_PORT" => "80",
45
+ "QUERY_STRING" => encode_www_form(properties[:params].to_a),
46
+ "HTTP_VERSION" => "HTTP/1.1",
47
+ "HTTP_USER_AGENT" => "spec",
48
+ "HTTP_HOST" => "spec.local",
49
+ "HTTP_ACCEPT_ENCODING" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
50
+ "HTTP_ACCEPT" => "*/*",
51
+ "HTTP_CONNECTION" => "close"
52
+ }.merge(additional_headers)
53
+
54
+ end
55
+
56
+ def encode_www_form(enum)
57
+ enum.map do |k, v|
58
+ if v.nil?
59
+ encode_www_form_component(k)
60
+ elsif v.respond_to?(:to_ary)
61
+ v.to_ary.map do |w|
62
+ str = encode_www_form_component(k)
63
+ unless w.nil?
64
+ str << '='
65
+ str << encode_www_form_component(w)
66
+ end
67
+ end.join('&')
68
+ else
69
+ str = encode_www_form_component(k)
70
+ str << '='
71
+ str << encode_www_form_component(v)
72
+ end
73
+ end.join('&')
74
+ end
75
+
76
+ TBLENCWWWCOMP_ = {} # :nodoc:
77
+ 256.times do |i|
78
+ TBLENCWWWCOMP_['%%%02X' % i] = i.chr
79
+ end
80
+ TBLENCWWWCOMP_[' '] = '+'
81
+ TBLENCWWWCOMP_.freeze
82
+ TBLDECWWWCOMP = {} # :nodoc:
83
+ 256.times do |i|
84
+ h, l = i>>4, i&15
85
+ TBLDECWWWCOMP[i.chr]= '%%%X%X' % [h, l]
86
+ TBLDECWWWCOMP[i.chr]= '%%%X%X' % [h, l]
87
+ TBLDECWWWCOMP[i.chr]= '%%%x%X' % [h, l]
88
+ TBLDECWWWCOMP[i.chr]= '%%%X%x' % [h, l]
89
+ TBLDECWWWCOMP[i.chr]= '%%%x%x' % [h, l]
90
+ end
91
+ TBLDECWWWCOMP['+'] = ' '
92
+ TBLDECWWWCOMP.freeze
93
+
94
+ def encode_www_form_component(str)
95
+ str = str.to_s.dup
96
+
97
+ TBLENCWWWCOMP_.each do |from,to|
98
+ str.gsub!(from,to)
99
+ end
100
+ str
101
+ end
102
+
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-03-09 00:00:00.000000000 Z
12
+ date: 2016-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - lib/rack/app/singleton_methods/route_handling.rb
115
115
  - lib/rack/app/singleton_methods/utility.rb
116
116
  - lib/rack/app/test.rb
117
+ - lib/rack/app/test/utils.rb
117
118
  - lib/rack/app/utils.rb
118
119
  - lib/rack/app/version.rb
119
120
  - rack-app.gemspec