corntrace-rack-contrib 1.0.2 → 1.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/contrib/jsonp.rb +6 -6
- data/lib/rack/contrib.rb +1 -1
- data/rack-contrib.gemspec +1 -1
- metadata +3 -2
data/lib/rack/contrib/jsonp.rb
CHANGED
@@ -24,7 +24,7 @@ module Rack
|
|
24
24
|
request = Rack::Request.new(env)
|
25
25
|
|
26
26
|
if is_json?(headers) && has_callback?(request)
|
27
|
-
status = translate_error_code
|
27
|
+
status = translate_error_code(status, response)
|
28
28
|
response = pad(request.params.delete('callback'), response)
|
29
29
|
|
30
30
|
# No longer json, its javascript!
|
@@ -43,6 +43,8 @@ module Rack
|
|
43
43
|
|
44
44
|
def is_json?(headers)
|
45
45
|
headers['Content-Type'].include?('application/json')
|
46
|
+
rescue
|
47
|
+
nil
|
46
48
|
end
|
47
49
|
|
48
50
|
def has_callback?(request)
|
@@ -64,13 +66,11 @@ module Rack
|
|
64
66
|
# Translate status code 40x and 50x to a json string in response, and change
|
65
67
|
# status code to 200. That because the jsonp's implemetation could not handler
|
66
68
|
# http status code when error occured, which could be meaningful in webservice.
|
67
|
-
def translate_error_code
|
69
|
+
def translate_error_code(status, response)
|
68
70
|
if status % 400 == 4 || status % 500 == 5
|
69
|
-
|
70
|
-
response[0] = %Q|{"errorCode":#{status}}|
|
71
|
-
status = 200
|
71
|
+
[200, [%Q|{"errorCode":#{status}}|]]
|
72
72
|
else
|
73
|
-
status
|
73
|
+
[status, response]
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
data/lib/rack/contrib.rb
CHANGED
data/rack-contrib.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'corntrace-rack-contrib'
|
6
|
-
s.version = '1.0.2'
|
6
|
+
s.version = '1.0.2.1'
|
7
7
|
s.date = '2010-07-18'
|
8
8
|
|
9
9
|
s.description = "Contributed Rack Middleware and Utilities"
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corntrace-rack-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 85
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 2
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 1.0.2.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Kevin Fu
|