rack-on-lambda 1.0.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: 0f7ad6d89db4356964720a3d68ffa9a1c653e98dacbc75fa92acd574207447c9
4
- data.tar.gz: 4ee99667a87bdbd3be31f7e9e7d5834c7395c738d50e55b41a2d9913b48a46dc
3
+ metadata.gz: 2b1760a77a950445a1b65fcdeb40408b3156ba5aee8ee6485e628093f9896fcf
4
+ data.tar.gz: d2eea02f03b1c853472e9f9dbe3884d62c61429c36db727ba0ed804367833050
5
5
  SHA512:
6
- metadata.gz: cf68a5117d15b831fb46d3b0cb6972f53eed0d8dd809b65021595182613517b31d55cbe048351ca135c02644977bcde09fbe785f3e70d8aa41474e8d5b468064
7
- data.tar.gz: 8a6e50798ec86cd68361c41e020bf519ec745e47868d38f3b69525392a2a1ba10737f84e71f22de2d9904be76ecd8b3e0a868726d1e2e946c962d3b4c9a2aadb
6
+ metadata.gz: 698443e9b170bb057b77efb098019ffce5bbb661235a2ee3a1168b8f22c3a9ad8804c0a12c7ce2b8d38ee5c83c8a1fb854b6eaadcf95208b5bf96ff0b10134f2
7
+ data.tar.gz: 5a4c851ba68ee0a3da18fe8444fdb47de924fd6c6d848f2f617b873a7b5cb06b6ab20ff58ea458d051666db9af2e8035b41aa88f9e0e7f356d7a1eb926a4a680
@@ -2,5 +2,8 @@
2
2
 
3
3
  #### Unreleased
4
4
 
5
+ #### 1.0.1
6
+ - [Fix] Encode the response body based on the `Content-Transfer-Encoding` header.
7
+
5
8
  #### 1.0.0
6
9
  - Initial release.
@@ -11,8 +11,8 @@ require 'pry' if Gem.loaded_specs.key?('pry')
11
11
 
12
12
  require_relative 'rack_on_lambda/version'
13
13
 
14
- require_relative 'rack_on_lambda/response'
15
14
  require_relative 'rack_on_lambda/query'
15
+ require_relative 'rack_on_lambda/adapters/responses/rest_api_response'
16
16
  require_relative 'rack_on_lambda/adapters/rest_api'
17
17
  require_relative 'rack_on_lambda/handlers/rest_api'
18
18
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RackOnLambda
4
+ module Adapters
5
+ module Responses
6
+ class RestApiResponse
7
+ def initialize(status, headers, body)
8
+ @status = status
9
+ @headers = headers
10
+ @body = stringify_body(body)
11
+ end
12
+
13
+ def as_json(_options = {})
14
+ {
15
+ 'statusCode' => status,
16
+ 'headers' => headers,
17
+ 'isBase64Encoded' => base64_encoded?,
18
+ 'body' => body
19
+ }
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :status, :headers, :body
25
+
26
+ def base64_encoded?
27
+ return @base64_encoded if defined?(@base64_encoded)
28
+
29
+ encoding = canonical_headers.fetch('content-transfer-encoding', '')
30
+ @base64_encoded = encoding.casecmp('binary').zero?
31
+ end
32
+
33
+ def canonical_headers
34
+ @canonical_headers ||= headers.transform_keys do |key|
35
+ key.to_s.downcase
36
+ end
37
+ end
38
+
39
+ def stringify_body(body)
40
+ result = ''
41
+ body.each { |chunk| result += chunk.to_s }
42
+
43
+ base64_encoded? ? Base64.strict_encode64(result) : result
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -18,7 +18,7 @@ module RackOnLambda
18
18
  end
19
19
 
20
20
  def response(status, headers, body)
21
- Response.new(status, headers, body).as_json
21
+ Responses::RestApiResponse.new(status, headers, body).as_json
22
22
  end
23
23
 
24
24
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RackOnLambda
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-on-lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2020-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -173,10 +173,10 @@ files:
173
173
  - gems.rb
174
174
  - lib/rack-on-lambda.rb
175
175
  - lib/rack_on_lambda.rb
176
+ - lib/rack_on_lambda/adapters/responses/rest_api_response.rb
176
177
  - lib/rack_on_lambda/adapters/rest_api.rb
177
178
  - lib/rack_on_lambda/handlers/rest_api.rb
178
179
  - lib/rack_on_lambda/query.rb
179
- - lib/rack_on_lambda/response.rb
180
180
  - lib/rack_on_lambda/version.rb
181
181
  - rack-on-lambda.gemspec
182
182
  homepage: https://github.com/Skudo/rack-on-lambda
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RackOnLambda
4
- class Response
5
- def initialize(status, headers, body)
6
- @status = status
7
- @headers = headers
8
- @body = stringify_body(body)
9
- end
10
-
11
- def as_json(_options = {})
12
- {
13
- 'statusCode' => @status,
14
- 'headers' => @headers,
15
- 'isBase64Encoded' => @base64_encoded,
16
- 'body' => @body
17
- }
18
- end
19
-
20
- private
21
-
22
- def stringify_body(body)
23
- result = ''
24
- body.each { |chunk| result += chunk.to_s }
25
-
26
- if result.ascii_only?
27
- @base64_encoded = false
28
- result
29
- else
30
- @base64_encoded = true
31
- Base64.strict_encode64(result)
32
- end
33
- end
34
- end
35
- end