webmachine 1.5.0 → 1.6.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
- SHA1:
3
- metadata.gz: 9309a2f44549ae1c912684fcdc7f60d31404bbf3
4
- data.tar.gz: 9531f40a275a2bf5e2bda7ed4816ff2463e4c234
2
+ SHA256:
3
+ metadata.gz: edddc1a3a4d7be22971484644cbf1bece06b2ba0f95ab5c8a3ed08cf485982b2
4
+ data.tar.gz: 4a1e642ad3fb3a1a57e8eee886393802f7b85f8ecb81bf9f06812577fe253840
5
5
  SHA512:
6
- metadata.gz: 5f5e9419fadcf121f8e0e80ec41417bd5dd9f096933aaf06793dd18d9d6ac6f5e2d028f56e0bc105ff5a87f9b2aa7ebc72e1d61424cc8c88d76e7cb92b9655a0
7
- data.tar.gz: d79442bba70911a7b704a26135a2fcadc4dbc1f0a0e12197d1ddbfb055498c54e164e972b03479d7428839ceef15bf32faa070b7ace58fc4b76704bdc5ec7bf8
6
+ metadata.gz: 89062ab939aadad0f1a41d3c3b85d030acf0e4668b5d06b0c65ad4a4425284bdaf60ece3af7e76f2b9eacc02cf2052f657cfb491372fef62463dad4324933617
7
+ data.tar.gz: 0a6078e13d68abaa7692675f5057e3b69d06dd5311d6e662a176490f427b6d1a1053bd3e5e0ed82fa9536eab421f05285e54939a2c900ca364347a361c21b21a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ### HEAD
2
2
 
3
+ ### 1.6.0 June 22, 2021
4
+
5
+ * fix: replace missed URI.decode with new Route.rfc3986_percent_decode (#261)
6
+ * fix: implement rfc3986 Percent-Encoding decoder
7
+ * feat: make rack env available on the webmachine request when using a rack adapter
8
+
3
9
  ### 1.5.0 September 8, 2017
10
+
4
11
  * Removed Fixnum/Integer deprecation warnings in Ruby 2.4
5
12
  * Fixed multiple cookie setting code
6
13
  * Added support for named captures
data/Gemfile CHANGED
@@ -12,11 +12,13 @@ group :test do
12
12
  gem "rspec-its", "~> 1.2"
13
13
  gem "rack", "~> 2.0"
14
14
  gem "rack-test", "~> 0.7"
15
+ gem "websocket_parser", "~>1.0"
15
16
  end
16
17
 
17
18
  group :webservers do
18
19
  gem 'reel', '~> 0.5.0'
19
20
  gem 'http', '~> 0.6.0'
21
+ gem 'celluloid', '0.17.4' # Refactors in 0.18.0 break the tests
20
22
  gem 'httpkit', :platform => [:mri, :rbx]
21
23
  end
22
24
 
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # webmachine for Ruby [![Build Status](https://travis-ci.org/webmachine/webmachine-ruby.svg)](https://travis-ci.org/webmachine/webmachine-ruby)
1
+ # webmachine for Ruby
2
+ [![Gem Version](https://badge.fury.io/rb/webmachine.svg)](https://badge.fury.io/rb/webmachine)
3
+ [![Build Status](https://travis-ci.org/webmachine/webmachine-ruby.svg)](https://travis-ci.org/webmachine/webmachine-ruby)
2
4
 
3
5
  webmachine-ruby is a port of
4
6
  [Webmachine](https://github.com/basho/webmachine), which is written in
@@ -92,12 +92,15 @@ end
92
92
  ```
93
93
 
94
94
  # POST to perform a task
95
- * Override `allowed_methods` and `process_post`. Put all the code to be executed in `process_post`.
96
- * `process_post` must return true, or the HTTP response code
97
- * Response headers like Content-Type will need to be set manually.
95
+ * Override `allowed_methods`, `process_post`, and `content_types_provided` (if the response has a content type).
96
+ * Rather than providing a method handler in the `content_type_provided` mappings, put all the code to be executed in `process_post`.
97
+ * `process_post` must return true, or the HTTP response code.
98
98
 
99
99
  ```ruby
100
100
  class DispatchOrderResource < Webmachine::Resource
101
+ def content_types_provided
102
+ [["application/json"]]
103
+ end
101
104
 
102
105
  def allowed_methods
103
106
  ["POST"]
@@ -108,9 +111,8 @@ class DispatchOrderResource < Webmachine::Resource
108
111
  end
109
112
 
110
113
  def process_post
111
- @order.dispatch
112
- response.headers['Content-Type'] = 'text/plain'
113
- response.body = "Successfully dispatched order #{id}"
114
+ @order.dispatch(params['some_param'])
115
+ response.body = { message: "Successfully dispatched order #{id}" }.to_json
114
116
  true
115
117
  end
116
118
 
@@ -119,6 +121,10 @@ class DispatchOrderResource < Webmachine::Resource
119
121
  def id
120
122
  request.path_info[:id]
121
123
  end
124
+
125
+ def params
126
+ JSON.parse(request.body.to_s)
127
+ end
122
128
  end
123
129
 
124
130
  ```
@@ -106,15 +106,25 @@ module Webmachine
106
106
 
107
107
  private
108
108
  def build_webmachine_request(rack_req, headers)
109
- Webmachine::Request.new(rack_req.request_method,
109
+ RackRequest.new(rack_req.request_method,
110
110
  rack_req.url,
111
111
  headers,
112
112
  RequestBody.new(rack_req),
113
113
  routing_tokens(rack_req),
114
- base_uri(rack_req)
114
+ base_uri(rack_req),
115
+ rack_req.env
115
116
  )
116
117
  end
117
118
 
119
+ class RackRequest < Webmachine::Request
120
+ attr_reader :env
121
+
122
+ def initialize(method, uri, headers, body, routing_tokens, base_uri, env)
123
+ super(method, uri, headers, body, routing_tokens, base_uri)
124
+ @env = env
125
+ end
126
+ end
127
+
118
128
  class RackResponse
119
129
  ONE_FIVE = '1.5'.freeze
120
130
 
@@ -59,8 +59,8 @@
59
59
  # Charset string
60
60
  CHARSET = 'Charset'.freeze
61
61
 
62
- # Semicolon split match
63
- SPLIT_SEMI = /\s*,\s*/.freeze
62
+ # Comma split match
63
+ SPLIT_COMMA = /\s*,\s*/.freeze
64
64
 
65
65
  # Star Character
66
66
  STAR = '*'.freeze
@@ -14,7 +14,7 @@ module Webmachine
14
14
  # appropriate media type.
15
15
  # @api private
16
16
  def choose_media_type(provided, header)
17
- types = Array(header).map{|h| h.split(SPLIT_SEMI) }.flatten
17
+ types = Array(header).map{|h| h.split(SPLIT_COMMA) }.flatten
18
18
  requested = MediaTypeList.build(types)
19
19
  provided = provided.map do |p| # normalize_provided
20
20
  MediaType.parse(p)
@@ -57,7 +57,7 @@ module Webmachine
57
57
  # @api private
58
58
  def choose_language(provided, header)
59
59
  if provided && !provided.empty?
60
- requested = PriorityList.build(header.split(SPLIT_SEMI))
60
+ requested = PriorityList.build(header.split(SPLIT_COMMA))
61
61
  star_priority = requested.priority_of(STAR)
62
62
  any_ok = star_priority && star_priority > 0.0
63
63
  accepted = requested.find do |priority, range|
@@ -99,7 +99,7 @@ module Webmachine
99
99
  # @api private
100
100
  def do_choose(choices, header, default)
101
101
  choices = choices.dup.map {|s| s.downcase }
102
- accepted = PriorityList.build(header.split(SPLIT_SEMI))
102
+ accepted = PriorityList.build(header.split(SPLIT_COMMA))
103
103
  default_priority = accepted.priority_of(default)
104
104
  star_priority = accepted.priority_of(STAR)
105
105
  default_ok = (default_priority.nil? && star_priority != 0.0) || default_priority
@@ -245,7 +245,7 @@ module Webmachine
245
245
 
246
246
  # ETag in If-Match
247
247
  def g11
248
- request_etags = request.if_match.split(SPLIT_SEMI).map {|etag| ETag.new(etag) }
248
+ request_etags = request.if_match.split(SPLIT_COMMA).map {|etag| ETag.new(etag) }
249
249
  request_etags.include?(ETag.new(resource.generate_etag)) ? :h10 : 412
250
250
  end
251
251
 
@@ -327,7 +327,7 @@ module Webmachine
327
327
 
328
328
  # Etag in if-none-match?
329
329
  def k13
330
- request_etags = request.if_none_match.split(SPLIT_SEMI).map {|etag| ETag.new(etag) }
330
+ request_etags = request.if_none_match.split(SPLIT_COMMA).map {|etag| ETag.new(etag) }
331
331
  resource_etag = resource.generate_etag
332
332
  if resource_etag && request_etags.include?(ETag.new(resource_etag))
333
333
  :j18
@@ -120,7 +120,7 @@ module Webmachine
120
120
  when tokens.empty?
121
121
  return false
122
122
  when Regexp === spec.first
123
- matches = spec.first.match URI.decode(tokens.first)
123
+ matches = spec.first.match Route.rfc3986_percent_decode(tokens.first)
124
124
  if matches
125
125
  if spec.first.named_captures.empty?
126
126
  bindings[:captures] = (bindings[:captures] || []) + matches.captures
@@ -134,7 +134,7 @@ module Webmachine
134
134
  return false
135
135
  end
136
136
  when Symbol === spec.first
137
- bindings[spec.first] = URI.decode(tokens.first)
137
+ bindings[spec.first] = Route.rfc3986_percent_decode(tokens.first)
138
138
  when spec.first == tokens.first
139
139
  else
140
140
  return false
@@ -145,6 +145,20 @@ module Webmachine
145
145
  end
146
146
  end
147
147
 
148
+ # Decode a string using the scheme described in RFC 3986 2.1. Percent-Encoding (https://www.ietf.org/rfc/rfc3986.txt)
149
+ def self.rfc3986_percent_decode(value)
150
+ s = StringScanner.new(value)
151
+ result = ''
152
+ until s.eos?
153
+ encoded_val = s.scan(/%([0-9a-fA-F]){2}/)
154
+ result << if encoded_val.nil?
155
+ s.getch
156
+ else
157
+ [encoded_val[1..-1]].pack('H*')
158
+ end
159
+ end
160
+ result
161
+ end
148
162
  end # class Route
149
163
  end # module Dispatcher
150
164
  end # module Webmachine
@@ -19,7 +19,8 @@ module Test
19
19
  ["test/response.fiberbody", :to_fiber],
20
20
  ["test/response.iobody", :to_io_body],
21
21
  ["test/response.cookies", :to_cookies],
22
- ["test/response.request_uri", :to_request_uri]
22
+ ["test/response.request_uri", :to_request_uri],
23
+ ["test/response.rack_env", :to_rack_env]
23
24
  ]
24
25
  end
25
26
 
@@ -75,5 +76,9 @@ module Test
75
76
  def to_request_uri
76
77
  request.uri.to_s
77
78
  end
79
+
80
+ def to_rack_env
81
+ request.env.to_json
82
+ end
78
83
  end
79
84
  end
@@ -1,6 +1,6 @@
1
1
  module Webmachine
2
2
  # Library version
3
- VERSION = "1.5.0".freeze
3
+ VERSION = "1.6.0".freeze
4
4
 
5
5
  # String for use in "Server" HTTP response header, which includes
6
6
  # the {VERSION}.
@@ -53,5 +53,10 @@ describe Webmachine::Adapters::Rack do
53
53
  rack_response = get "test", nil, {"HTTP_ACCEPT" => "test/response.request_uri"}
54
54
  expect(rack_response.body).to eq "http://example.org/test"
55
55
  end
56
+
57
+ it "provides the rack env on the request" do
58
+ rack_response = get "test", nil, {"HTTP_ACCEPT" => "test/response.rack_env"}
59
+ expect(JSON.parse(rack_response.body).keys).to include "rack.input"
60
+ end
56
61
  end
57
62
  end
@@ -106,7 +106,7 @@ describe Webmachine::Decision::FSM do
106
106
  end
107
107
 
108
108
  it 'does not call resource.finish_request again' do
109
- expect(resource).to_not receive(:finish_request).once { raise }
109
+ expect(resource).to receive(:finish_request).once
110
110
  run_with_exception
111
111
  end
112
112
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Webmachine::Dispatcher::Route do
4
+ describe '#rfc3986_percent_decode' do
5
+ def call_subject(value)
6
+ Webmachine::Dispatcher::Route.rfc3986_percent_decode(value)
7
+ end
8
+
9
+ it 'does not change un-encoded strings' do
10
+ expect(call_subject('this is a normal string, I think')).to eq 'this is a normal string, I think'
11
+ expect(call_subject('')).to eq ''
12
+ end
13
+
14
+ it 'decodes percent encoded sequences' do
15
+ expect(call_subject('/tenants/esckimo+test%20%65')).to eq '/tenants/esckimo+test e'
16
+ end
17
+
18
+ it 'leaves incorrectly encoded sequences as is' do
19
+ expect(call_subject('/tenants/esckimo+test%2%65')).to eq '/tenants/esckimo+test%2e'
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Cribbs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -70,7 +70,6 @@ files:
70
70
  - README.md
71
71
  - RELEASING.md
72
72
  - Rakefile
73
- - bethtemp
74
73
  - documentation/adapters.md
75
74
  - documentation/authentication-and-authorization.md
76
75
  - documentation/configurator.md
@@ -148,7 +147,6 @@ files:
148
147
  - lib/webmachine/translation.rb
149
148
  - lib/webmachine/version.rb
150
149
  - memory_test.rb
151
- - pkg/webmachine-1.5.0.gem
152
150
  - spec/spec_helper.rb
153
151
  - spec/webmachine/adapter_spec.rb
154
152
  - spec/webmachine/adapters/httpkit_spec.rb
@@ -165,6 +163,7 @@ files:
165
163
  - spec/webmachine/decision/flow_spec.rb
166
164
  - spec/webmachine/decision/fsm_spec.rb
167
165
  - spec/webmachine/decision/helpers_spec.rb
166
+ - spec/webmachine/dispatcher/rfc3986_percent_decode_spec.rb
168
167
  - spec/webmachine/dispatcher/route_spec.rb
169
168
  - spec/webmachine/dispatcher_spec.rb
170
169
  - spec/webmachine/errors_spec.rb
@@ -185,7 +184,7 @@ homepage: http://github.com/seancribbs/webmachine-ruby
185
184
  licenses:
186
185
  - Apache-2.0
187
186
  metadata: {}
188
- post_install_message:
187
+ post_install_message:
189
188
  rdoc_options: []
190
189
  require_paths:
191
190
  - lib
@@ -200,41 +199,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
199
  - !ruby/object:Gem::Version
201
200
  version: '0'
202
201
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.6.11
205
- signing_key:
202
+ rubygems_version: 3.1.4
203
+ signing_key:
206
204
  specification_version: 4
207
205
  summary: webmachine is a toolkit for building HTTP applications,
208
206
  test_files:
209
207
  - spec/spec_helper.rb
208
+ - spec/webmachine/trace/fsm_spec.rb
209
+ - spec/webmachine/trace/resource_proxy_spec.rb
210
+ - spec/webmachine/trace/trace_store_spec.rb
211
+ - spec/webmachine/configuration_spec.rb
212
+ - spec/webmachine/dispatcher/route_spec.rb
213
+ - spec/webmachine/dispatcher/rfc3986_percent_decode_spec.rb
214
+ - spec/webmachine/rescueable_exception_spec.rb
215
+ - spec/webmachine/etags_spec.rb
216
+ - spec/webmachine/chunked_body_spec.rb
210
217
  - spec/webmachine/adapter_spec.rb
211
- - spec/webmachine/adapters/httpkit_spec.rb
212
- - spec/webmachine/adapters/rack_mapped_spec.rb
213
- - spec/webmachine/adapters/rack_spec.rb
218
+ - spec/webmachine/headers_spec.rb
214
219
  - spec/webmachine/adapters/reel_spec.rb
220
+ - spec/webmachine/adapters/rack_spec.rb
221
+ - spec/webmachine/adapters/httpkit_spec.rb
215
222
  - spec/webmachine/adapters/webrick_spec.rb
216
- - spec/webmachine/application_spec.rb
217
- - spec/webmachine/chunked_body_spec.rb
218
- - spec/webmachine/configuration_spec.rb
219
- - spec/webmachine/cookie_spec.rb
220
- - spec/webmachine/decision/conneg_spec.rb
223
+ - spec/webmachine/adapters/rack_mapped_spec.rb
224
+ - spec/webmachine/request_spec.rb
225
+ - spec/webmachine/response_spec.rb
226
+ - spec/webmachine/decision/fsm_spec.rb
221
227
  - spec/webmachine/decision/falsey_spec.rb
222
228
  - spec/webmachine/decision/flow_spec.rb
223
- - spec/webmachine/decision/fsm_spec.rb
224
229
  - spec/webmachine/decision/helpers_spec.rb
225
- - spec/webmachine/dispatcher/route_spec.rb
226
- - spec/webmachine/dispatcher_spec.rb
227
- - spec/webmachine/errors_spec.rb
228
- - spec/webmachine/etags_spec.rb
229
- - spec/webmachine/events_spec.rb
230
- - spec/webmachine/headers_spec.rb
230
+ - spec/webmachine/decision/conneg_spec.rb
231
+ - spec/webmachine/cookie_spec.rb
231
232
  - spec/webmachine/media_type_spec.rb
232
- - spec/webmachine/request_spec.rb
233
- - spec/webmachine/rescueable_exception_spec.rb
233
+ - spec/webmachine/errors_spec.rb
234
234
  - spec/webmachine/resource/authentication_spec.rb
235
- - spec/webmachine/response_spec.rb
236
- - spec/webmachine/trace/fsm_spec.rb
237
- - spec/webmachine/trace/resource_proxy_spec.rb
238
- - spec/webmachine/trace/trace_store_spec.rb
239
235
  - spec/webmachine/trace_spec.rb
236
+ - spec/webmachine/application_spec.rb
237
+ - spec/webmachine/events_spec.rb
238
+ - spec/webmachine/dispatcher_spec.rb
240
239
  - ".gitignore"
data/bethtemp DELETED
@@ -1,3 +0,0 @@
1
- * use Integer instead of Fixnum (removes deprecation warnings in Ruby 2.4)
2
- * Fixing multiple cookie setting code
3
- * Added support for named captures