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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1760a77a950445a1b65fcdeb40408b3156ba5aee8ee6485e628093f9896fcf
|
4
|
+
data.tar.gz: d2eea02f03b1c853472e9f9dbe3884d62c61429c36db727ba0ed804367833050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 698443e9b170bb057b77efb098019ffce5bbb661235a2ee3a1168b8f22c3a9ad8804c0a12c7ce2b8d38ee5c83c8a1fb854b6eaadcf95208b5bf96ff0b10134f2
|
7
|
+
data.tar.gz: 5a4c851ba68ee0a3da18fe8444fdb47de924fd6c6d848f2f617b873a7b5cb06b6ab20ff58ea458d051666db9af2e8035b41aa88f9e0e7f356d7a1eb926a4a680
|
data/changelog.md
CHANGED
data/lib/rack_on_lambda.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|