rack-cargo 0.9.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18247c076dabaec48022379801e52ce2c0f42b7d
4
- data.tar.gz: ac28a8c8840c795e602269072b6047969b092b86
3
+ metadata.gz: 048340003319fa2ae901fbdbb95093b0350aa6a5
4
+ data.tar.gz: 1ab67a556f070ed792dacf24a0be83f989eb6bdb
5
5
  SHA512:
6
- metadata.gz: 7b0c706fe67a05b6bc27555d3387c42cae772fa35c8f1f3fa62b5d43cc788dc3ce15c2bb9bd1a8d8ca9f1be8b7da031065e95c55968df3d54558a340f9fc4da0
7
- data.tar.gz: 7ee5d82be0ef27a7cf6bf5946d6cd2f823c47c4d656ab1debcfe9da043be415a2600962b2f8f24334500aae936d2c25c7a63babbf82f9d373b6ce6e41a2887e5
6
+ metadata.gz: e8b80851dd86f64cdff6360f1b495b4e46ec6344cefc6bfc46ccd81d7d52d95e96b39a52393cfa056c1878875d71e222fbf19050de24352a0a15260bbf81dc6e
7
+ data.tar.gz: 2cae3f111f66c09a810f88cf3eed7045aa21584db941f43a6b76041b2878b2b70d4a8aebdebf64b3744e83a22829345f5f42548f9d8e9c52c5b3ad08f7649716
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
5
- - 2.4.0
4
+ - 2.3.1
5
+ - 2.4.1
6
6
  before_install: gem install bundler -v 1.15.3
data/README.md CHANGED
@@ -32,7 +32,9 @@ Or install it yourself as:
32
32
 
33
33
  $ gem install rack-cargo
34
34
 
35
- ## Usage (TODO)
35
+ ## Usage
36
+
37
+ Regarding individual requests, `rack-cargo` tries to follow the [Rack SPEC](https://www.rubydoc.info/github/rack/rack/file/SPEC). If you find any mismatches, feel free to open an issue or a pull request.
36
38
 
37
39
  ### Configuration
38
40
 
@@ -139,14 +141,14 @@ module MyFeeder
139
141
  state.store(:data, "Useful data to MyEater")
140
142
  end
141
143
  end
142
-
144
+
143
145
  module MyEater
144
146
  def self.call(request, state)
145
147
  data = state.fetch(:data)
146
148
  # do something with the data
147
149
  end
148
150
  end
149
-
151
+
150
152
  Rack::Cargo.configure do |config|
151
153
  config.processors.insert(2, MyFeeder) # insert into third position
152
154
  config.processors.insert(3, MyEater) # insert into fourth position
@@ -169,6 +171,14 @@ end
169
171
 
170
172
  Timed out requests' response is with status 504 (Gateway timeout) and with empty headers, body.
171
173
 
174
+ ### `nil` body in an individual request
175
+
176
+ In case an individual requests' body is `nil`, it will be sent downstream as `""` (empty `String`).
177
+
178
+ ### No body in an individual response
179
+
180
+ In case an individual request receives a response without a body (as empty `String`), it will be sent upstream as `nil`.
181
+
172
182
  ## Development
173
183
 
174
184
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -177,7 +187,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
177
187
 
178
188
  ## Contributing
179
189
 
180
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-cargo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
190
+ Bug reports and pull requests are welcome on GitHub at https://github.com/murdho/rack-cargo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
181
191
 
182
192
  ## License
183
193
 
@@ -185,4 +195,4 @@ The gem is available as open source under the terms of the [MIT License](http://
185
195
 
186
196
  ## Code of Conduct
187
197
 
188
- Everyone interacting in the Rack::Cargo project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rack-cargo/blob/master/CODE_OF_CONDUCT.md).
198
+ Everyone interacting in the Rack::Cargo project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/murdho/rack-cargo/blob/master/CODE_OF_CONDUCT.md).
@@ -12,6 +12,8 @@ module Rack
12
12
  class << self
13
13
  def call(request, state)
14
14
  REFERENCING_ENABLED.each do |attribute_key|
15
+ next if request.fetch(attribute_key).nil?
16
+
15
17
  element, converted_to_json = get_json_element(request, attribute_key)
16
18
  placeholders = find_placeholders(element)
17
19
 
@@ -5,16 +5,29 @@ require "rack/cargo/core_ext/deep_dup"
5
5
  module Rack
6
6
  module Cargo
7
7
  module RequestEnvBuilder
8
- def self.call(request, state)
9
- request_env = state.fetch(:env).deep_dup
8
+ class << self
9
+ def call(request, state)
10
+ request_env = state.fetch(:env).deep_dup
10
11
 
11
- path, query_string = request[REQUEST_PATH].split("?", 2)
12
- request_env[ENV_PATH] = path
13
- request_env[ENV_QUERY_STRING] = query_string || ""
14
- request_env[ENV_METHOD] = request[REQUEST_METHOD]
15
- request_env[ENV_INPUT] = StringIO.new(request[REQUEST_BODY].to_json)
12
+ path, query_string = request[REQUEST_PATH].split("?", 2)
13
+ request_env[ENV_PATH] = path
14
+ request_env[ENV_QUERY_STRING] = query_string || ""
15
+ request_env[ENV_METHOD] = request[REQUEST_METHOD]
16
+ request_env[ENV_INPUT] = StringIO.new(
17
+ io_input_from_request_body(request[REQUEST_BODY])
18
+ )
16
19
 
17
- state[:request_env] = request_env
20
+ state[:request_env] = request_env
21
+ end
22
+
23
+ private
24
+
25
+ # Returns request_body as JSON if it's not nil,
26
+ # otherwise returns empty string.
27
+ def io_input_from_request_body(request_body)
28
+ return "" if request_body.nil?
29
+ request_body.to_json
30
+ end
18
31
  end
19
32
  end
20
33
  end
@@ -29,6 +29,7 @@ module Rack
29
29
  def response_body(app_response_body)
30
30
  response_string = ""
31
31
  app_response_body.each { |piece| response_string += piece }
32
+ return if response_string.empty?
32
33
 
33
34
  JSON.parse(response_string)
34
35
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  module Cargo
5
- VERSION = "0.9.1"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cargo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murdho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler