skooma 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -1
- data/lib/skooma/body_parsers.rb +2 -2
- data/lib/skooma/env_mapper.rb +11 -2
- data/lib/skooma/instance.rb +8 -8
- data/lib/skooma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8caa0911924b17126cad7544d4c54e4fe3f819c6b21c3489cd47180bb69996
|
4
|
+
data.tar.gz: 052a2f72272a02b99cb44f62b6a1b1a319ca1c743742c66125d4da4ae9b402c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4392d35e7aade0d2683f38ef782ed6b2b980aee835ea489f173202ff75627a4cff4bc3ae522bb9e06ed6b69d7b073a08520902a3a6388cd22f3e8321bbedbb08
|
7
|
+
data.tar.gz: 990bfcb689cd4ad8f76060c955abf9ce01fd3513a54499592136045d1f87f3000575356b1d0e7ddea78b16cc76e516d099dfeda18c35c36426a6426e933068ea
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2024-04-09
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- BREAKING CHANGE: Pass `headers` parameter to registered `BodyParsers`. ([@skryukov])
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# Before:
|
18
|
+
Skooma::BodyParsers.register("application/xml", ->(body) { Hash.from_xml(body) })
|
19
|
+
# After:
|
20
|
+
Skooma::BodyParsers.register("application/xml", ->(body, headers:) { Hash.from_xml(body) })
|
21
|
+
```
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
- Fix wrong path when combined with Rails exceptions_app. ([@ursm])
|
25
|
+
|
10
26
|
## [0.2.3] - 2024-01-18
|
11
27
|
|
12
28
|
### Added
|
@@ -68,8 +84,10 @@ end
|
|
68
84
|
- Initial implementation. ([@skryukov])
|
69
85
|
|
70
86
|
[@skryukov]: https://github.com/skryukov
|
87
|
+
[@ursm]: https://github.com/ursm
|
71
88
|
|
72
|
-
[Unreleased]: https://github.com/skryukov/skooma/compare/v0.
|
89
|
+
[Unreleased]: https://github.com/skryukov/skooma/compare/v0.3.0...HEAD
|
90
|
+
[0.3.0]: https://github.com/skryukov/skooma/compare/v0.2.3...v0.3.0
|
73
91
|
[0.2.3]: https://github.com/skryukov/skooma/compare/v0.2.2...v0.2.3
|
74
92
|
[0.2.2]: https://github.com/skryukov/skooma/compare/v0.2.1...v0.2.2
|
75
93
|
[0.2.1]: https://github.com/skryukov/skooma/compare/v0.2.0...v0.2.1
|
data/lib/skooma/body_parsers.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Skooma
|
4
4
|
module BodyParsers
|
5
5
|
class << self
|
6
|
-
DEFAULT_PARSER = ->(body) { body }
|
6
|
+
DEFAULT_PARSER = ->(body, **_options) { body }
|
7
7
|
|
8
8
|
def [](media_type)
|
9
9
|
parsers[media_type.to_s.strip.downcase] || DEFAULT_PARSER
|
@@ -20,7 +20,7 @@ module Skooma
|
|
20
20
|
self.parsers = {}
|
21
21
|
|
22
22
|
module JSONParser
|
23
|
-
def self.call(body)
|
23
|
+
def self.call(body, **_options)
|
24
24
|
JSON.parse(body)
|
25
25
|
rescue JSON::ParserError
|
26
26
|
body
|
data/lib/skooma/env_mapper.rb
CHANGED
@@ -9,7 +9,7 @@ module Skooma
|
|
9
9
|
def call(env, response = nil, with_response: true, with_request: true)
|
10
10
|
result = {
|
11
11
|
"method" => env["REQUEST_METHOD"].downcase,
|
12
|
-
"path" => env["PATH_INFO"]
|
12
|
+
"path" => env["action_dispatch.original_path"] || env["PATH_INFO"]
|
13
13
|
}
|
14
14
|
result["request"] = map_request(env) if with_request
|
15
15
|
result["response"] = map_response(response) if response && with_response
|
@@ -23,10 +23,19 @@ module Skooma
|
|
23
23
|
{
|
24
24
|
"query" => env["rack.request.query_string"] || env["QUERY_STRING"],
|
25
25
|
"headers" => env.select { |k, _| k.start_with?("HTTP_") || PLAIN_HEADERS.include?(k) }.transform_keys { |k| k.sub(REGEXP_HTTP, "").split("_").map(&:capitalize).join("-") },
|
26
|
-
"body" => env["RAW_POST_DATA"]
|
26
|
+
"body" => env["RAW_POST_DATA"] || read_rack_input(env["rack.input"])
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
|
+
def read_rack_input(input)
|
31
|
+
return nil unless input.respond_to?(:rewind)
|
32
|
+
|
33
|
+
input.rewind
|
34
|
+
raw_input = input.read
|
35
|
+
input.rewind
|
36
|
+
raw_input
|
37
|
+
end
|
38
|
+
|
30
39
|
def map_response(response)
|
31
40
|
status, headers, body = response.to_a
|
32
41
|
full_body = +""
|
data/lib/skooma/instance.rb
CHANGED
@@ -63,16 +63,16 @@ module Skooma
|
|
63
63
|
data = {}
|
64
64
|
data["status"] = JSONSkooma::JSONNode.new(value.fetch("status"), key: "status", parent: self)
|
65
65
|
data["headers"] = Headers.new(value.fetch("headers", {}), key: "headers", parent: self)
|
66
|
-
body_value = parse_body(value["body"], data["headers"]
|
66
|
+
body_value = parse_body(value["body"], data["headers"])
|
67
67
|
data["body"] = Attribute.new(body_value, key: "body", parent: self)
|
68
68
|
["object", data]
|
69
69
|
end
|
70
70
|
|
71
|
-
def parse_body(body,
|
71
|
+
def parse_body(body, headers)
|
72
72
|
return nil unless body
|
73
73
|
|
74
|
-
parser = BodyParsers[
|
75
|
-
parser ? parser.call(body) : body
|
74
|
+
parser = BodyParsers[headers["Content-Type"]&.value&.split(";")&.first]
|
75
|
+
parser ? parser.call(body, headers: headers) : body
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -83,16 +83,16 @@ module Skooma
|
|
83
83
|
data = {}
|
84
84
|
data["query"] = Attribute.new(value.fetch("query", ""), key: "query", parent: self)
|
85
85
|
data["headers"] = Headers.new(value.fetch("headers", {}), key: "headers", parent: self)
|
86
|
-
body_value = parse_body(value["body"], data["headers"]
|
86
|
+
body_value = parse_body(value["body"], data["headers"])
|
87
87
|
data["body"] = Attribute.new(body_value, key: "body", parent: self)
|
88
88
|
["object", data]
|
89
89
|
end
|
90
90
|
|
91
|
-
def parse_body(body,
|
91
|
+
def parse_body(body, headers)
|
92
92
|
return nil unless body
|
93
93
|
|
94
|
-
parser = BodyParsers[
|
95
|
-
parser ? parser.call(body) : body
|
94
|
+
parser = BodyParsers[headers["Content-Type"]&.value&.split(";")&.first]
|
95
|
+
parser ? parser.call(body, headers: headers) : body
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
data/lib/skooma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skooma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|