rack-kibo 0.1.0 → 0.1.3
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 +4 -4
- data/README.md +14 -3
- data/lib/rack/kibo/kibo.rb +10 -6
- data/lib/rack/kibo/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c6feb1f6c676fa421f6438876465f71e7e044c9
|
4
|
+
data.tar.gz: 9aef1da99f5d22509a07c06c13c01ed30f930a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 785a20736e9f72241d23f5142a9bb65ddf5787933a0de36b7a9d00efc87a51ea14d1ce9b5138853ae9823589ad052233a1e7aec8f8b9c8429284f2557267ac28
|
7
|
+
data.tar.gz: 1ce99f61b09c76bc02656420ba465b46652988f040d5e62fe23b3640af48113c79b348eaeba42506c4b8e77b42947f89cc26ed54b04d6ae879a7fad3e2399d01
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## What Kibo Does
|
22
22
|
|
23
|
-
Kibo will wrap any request for,or response containing the JSON
|
23
|
+
Kibo will wrap any request for JSON, or response containing the JSON
|
24
24
|
Content-Type `application/json` in a simple structured JSON object:
|
25
25
|
|
26
26
|
```javascript
|
@@ -37,8 +37,8 @@ Content-Type `application/json` in a simple structured JSON object:
|
|
37
37
|
|
38
38
|
Kibo will always return a successful HTTP Status code (anything less
|
39
39
|
than 400) unless there was an error within Kibo itself. If the response
|
40
|
-
from your server is an error code, Kibo returns HTTP 200, with the
|
41
|
-
|
40
|
+
from your server is an error code, Kibo returns HTTP 200, with the `success`
|
41
|
+
property of `false`
|
42
42
|
|
43
43
|
|
44
44
|
## Getting Started
|
@@ -47,7 +47,11 @@ from your server is an error code, Kibo returns HTTP 200, with the
|
|
47
47
|
|
48
48
|
Add the middleware to your Rack app
|
49
49
|
|
50
|
+
|
51
|
+
|
50
52
|
```ruby
|
53
|
+
require 'rack/kibo'
|
54
|
+
|
51
55
|
use Rack::Kibo
|
52
56
|
```
|
53
57
|
|
@@ -87,6 +91,13 @@ or uppercase 'V'
|
|
87
91
|
Kibo works for any request path, but will return a version of `0` if it
|
88
92
|
does not find version information from the request path
|
89
93
|
|
94
|
+
## Changes
|
95
|
+
|
96
|
+
- **0.1.3** Removes `Content-Length` computation, lets `Rack` handle it
|
97
|
+
internally
|
98
|
+
- **0.1.2** Support matching on `content-type` when multiple types are
|
99
|
+
supplied
|
100
|
+
|
90
101
|
## Development
|
91
102
|
|
92
103
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rack/kibo/kibo.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
class SomethingTest
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
4
|
module Rack
|
9
5
|
##
|
10
6
|
# Rack Middleware which presents a clean API to JSON responses
|
@@ -19,6 +15,7 @@ module Rack
|
|
19
15
|
##
|
20
16
|
# Standard JSON content-type
|
21
17
|
JSON_CONTENT_TYPE = "application/json"
|
18
|
+
JSON_CONTENT_TYPE_REGEX = /application\/json/
|
22
19
|
|
23
20
|
##
|
24
21
|
# Creates a new instance of the CleanApi middleware
|
@@ -67,10 +64,15 @@ module Rack
|
|
67
64
|
:body => create_payload(response[2])
|
68
65
|
}
|
69
66
|
response[2] = [ rs.to_json ]
|
70
|
-
response[1]["Content-Length"] = response[2][0].length.to_s
|
71
67
|
|
68
|
+
# Let Rack compute the content-length
|
69
|
+
#response[1]["Content-Length"] = response[2][0].length.to_s
|
70
|
+
response[1].delete("Content-Length")
|
72
71
|
# TODO: support an option to allow user to emit original status codes
|
73
72
|
|
73
|
+
# if there is an error, then respond with a 200
|
74
|
+
# so browser promises return as success responses
|
75
|
+
# instead of errors
|
74
76
|
response[0] = 200 unless rs[:success]
|
75
77
|
response
|
76
78
|
end
|
@@ -87,6 +89,8 @@ module Rack
|
|
87
89
|
server_result = result[2]
|
88
90
|
end
|
89
91
|
response = create_error_json(error, server_result)
|
92
|
+
# should send json content-type
|
93
|
+
rsp_env["Content-Type"] = JSON_CONTENT_TYPE
|
90
94
|
end
|
91
95
|
error_result = [500, rsp_env, [response]]
|
92
96
|
end
|
@@ -156,7 +160,7 @@ module Rack
|
|
156
160
|
# response should be wrapped in the CleanApi
|
157
161
|
def is_supported_content_type?(content_type)
|
158
162
|
# TODO: Should we allow user-defined accept-encodings?
|
159
|
-
content_type
|
163
|
+
content_type =~ JSON_CONTENT_TYPE_REGEX ? true : false
|
160
164
|
end
|
161
165
|
|
162
166
|
end
|
data/lib/rack/kibo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-kibo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marshall Mickelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.6.11
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: A Rack Middleware to present structured JSON responses
|