rack-app 5.5.1 → 5.6.0

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
  SHA1:
3
- metadata.gz: b4b3d25d410555551a8d81c6be4c797cb28d9a2b
4
- data.tar.gz: 6b4c65de92a11cfcf01d7a613674797e855a0ffa
3
+ metadata.gz: d01a4b973a8a3b61c3fac65895cea447902368e0
4
+ data.tar.gz: 1661ab7a248eeb8d7df8cc65f23348ea9cf7c666
5
5
  SHA512:
6
- metadata.gz: d84f255799c2c240f6245732a2ae00701c25584bb9eb37797206bbc88a2b69f3584d5ca441638699d7e5c33e090f24f2d3b84ebc564a170e85f420fd917a8386
7
- data.tar.gz: 1a0db3ae2452a57f87c11f02613f8491b3659131d2af2d61ac41f1ec7ab0d0eb0599ffdb510fac27188c91f5b220f214dab0754386a72690d5591b338eac1363
6
+ metadata.gz: 0044dac4f6b279fd9f3d00d43bbba4ee86791fe40e7028999d8dbe1faf1164fa3c5918491e6ad2c3a7d76ed44c69e70033b7de8f41b73eae3067ff8e98fecc1f
7
+ data.tar.gz: f452f8899a4067484d63574ca9655b172813af4b7787865a846db8e5b37d0988a5f2487393fa3bdff209a6017b57e8b1a91e281eeae79b8770b1bbeb34ce2cec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.5.1
1
+ 5.6.0
@@ -1,5 +1,7 @@
1
1
  module Rack::App::Constants
2
2
 
3
+ require "rack/app/constants/http_status_codes"
4
+
3
5
  def self.rack_constant(constant_name, fallback_value)
4
6
  ::Rack.const_get(constant_name)
5
7
  rescue NameError
@@ -0,0 +1,65 @@
1
+ module Rack::App::Constants
2
+ HTTP_STATUS_CODES = {
3
+ 100 => "Continue",
4
+ 101 => "Switching Protocols",
5
+ 102 => "Processing (WebDAV; RFC 2518)",
6
+ 200 => "OK",
7
+ 201 => "Created",
8
+ 202 => "Accepted",
9
+ 203 => "Non-Authoritative Information (since HTTP/1.1)",
10
+ 204 => "", # No Content
11
+ 205 => "", # Reset Content
12
+ 206 => "Partial Content (RFC 7233)",
13
+ 207 => "Multi-Status (WebDAV; RFC 4918)",
14
+ 208 => "Already Reported (WebDAV; RFC 5842)",
15
+ 226 => "IM Used (RFC 3229)",
16
+ 300 => "Multiple Choices",
17
+ 301 => "Moved Permanently",
18
+ 302 => "Found",
19
+ 303 => "See Other (since HTTP/1.1)",
20
+ 304 => "", # Not Modified (RFC 7232)
21
+ 305 => "Use Proxy (since HTTP/1.1)",
22
+ 306 => "Switch Proxy",
23
+ 307 => "Temporary Redirect (since HTTP/1.1)",
24
+ 308 => "Permanent Redirect (RFC 7538)",
25
+ 400 => "Bad Request",
26
+ 401 => "Unauthorized (RFC 7235)",
27
+ 402 => "Payment Required",
28
+ 403 => "Forbidden",
29
+ 404 => "Not Found",
30
+ 405 => "Method Not Allowed",
31
+ 406 => "Not Acceptable",
32
+ 407 => "Proxy Authentication Required (RFC 7235)",
33
+ 408 => "Request Timeout",
34
+ 409 => "Conflict",
35
+ 410 => "Gone",
36
+ 411 => "Length Required",
37
+ 412 => "Precondition Failed (RFC 7232)",
38
+ 413 => "Payload Too Large (RFC 7231)",
39
+ 414 => "URI Too Long (RFC 7231)",
40
+ 415 => "Unsupported Media Type",
41
+ 416 => "Range Not Satisfiable (RFC 7233)",
42
+ 417 => "Expectation Failed",
43
+ 418 => "I'm a teapot (RFC 2324)",
44
+ 421 => "Misdirected Request (RFC 7540)",
45
+ 422 => "Unprocessable Entity (WebDAV; RFC 4918)",
46
+ 423 => "Locked (WebDAV; RFC 4918)",
47
+ 424 => "Failed Dependency (WebDAV; RFC 4918)",
48
+ 426 => "Upgrade Required",
49
+ 428 => "Precondition Required (RFC 6585)",
50
+ 429 => "Too Many Requests (RFC 6585)",
51
+ 431 => "Request Header Fields Too Large (RFC 6585)",
52
+ 451 => "Unavailable For Legal Reasons",
53
+ 500 => "Internal Server Error",
54
+ 501 => "Not Implemented",
55
+ 502 => "Bad Gateway",
56
+ 503 => "Service Unavailable",
57
+ 504 => "Gateway Timeout",
58
+ 505 => "HTTP Version Not Supported",
59
+ 506 => "Variant Also Negotiates (RFC 2295)",
60
+ 507 => "Insufficient Storage (WebDAV; RFC 4918)",
61
+ 508 => "Loop Detected (WebDAV; RFC 5842)",
62
+ 510 => "Not Extended (RFC 2774)",
63
+ 511 => "Network Authentication Required (RFC 6585)",
64
+ }.freeze
65
+ end
@@ -1,13 +1,15 @@
1
1
  module Rack::App::InstanceMethods
2
2
 
3
3
  require 'rack/app/instance_methods/core'
4
- require 'rack/app/instance_methods/http_control'
4
+ require 'rack/app/instance_methods/http_status'
5
+ require 'rack/app/instance_methods/redirect_to'
5
6
  require 'rack/app/instance_methods/payload'
6
7
  require 'rack/app/instance_methods/serve_file'
7
8
  require 'rack/app/instance_methods/streaming'
8
9
 
9
10
  include Rack::App::InstanceMethods::Core
10
- include Rack::App::InstanceMethods::HttpControl
11
+ include Rack::App::InstanceMethods::HTTPStatus
12
+ include Rack::App::InstanceMethods::RedirectTo
11
13
  include Rack::App::InstanceMethods::Payload
12
14
  include Rack::App::InstanceMethods::ServeFile
13
15
  include Rack::App::InstanceMethods::Streaming
@@ -18,8 +18,11 @@ module Rack::App::InstanceMethods::Core
18
18
  @response || raise("response object is not set for #{self.class}")
19
19
  end
20
20
 
21
- def finish_response
22
- throw(:rack_response, response)
21
+ def finish!(rack_response=response)
22
+ throw(:rack_response, rack_response)
23
23
  end
24
24
 
25
+ alias finish_response finish!
26
+ Rack::App::Utils.deprecate(self, :finish_response, :finish!, 2016,9)
27
+
25
28
  end
@@ -0,0 +1,10 @@
1
+ module Rack::App::InstanceMethods::HTTPStatus
2
+
3
+ def http_status!(code, desc=nil)
4
+ raise unless code.is_a?(Integer)
5
+ response.status = code
6
+ response.write(desc || Rack::App::Constants::HTTP_STATUS_CODES[code] || raise)
7
+ finish!
8
+ end
9
+
10
+ end
@@ -1,4 +1,4 @@
1
- module Rack::App::InstanceMethods::HttpControl
1
+ module Rack::App::InstanceMethods::RedirectTo
2
2
 
3
3
  def redirect_to(url, params={})
4
4
 
@@ -12,8 +12,8 @@ module Rack::App::InstanceMethods::HttpControl
12
12
  response.status = 301
13
13
  response.headers.merge!({'Location' => url})
14
14
 
15
- finish_response
16
-
15
+ finish!
16
+
17
17
  end
18
18
 
19
19
  end
@@ -5,7 +5,7 @@ module Rack::App::InstanceMethods::ServeFile
5
5
  response.status = raw_rack_resp[0]
6
6
  response.headers.merge!(raw_rack_resp[1])
7
7
  response.body = raw_rack_resp[2]
8
- finish_response
8
+ finish!
9
9
  end
10
10
 
11
11
  end
@@ -11,6 +11,6 @@ module Rack::App::InstanceMethods::Streaming
11
11
  # servers like Thin or Rainbows.
12
12
  def stream(keep_open = false, &back)
13
13
  response.body = Rack::App::Streamer.new(request.env, :keep_open => keep_open, &back)
14
- finish_response
14
+ finish!
15
15
  end
16
16
  end
@@ -1,4 +1,5 @@
1
1
  module Rack::App::Middlewares::Hooks
2
+ require "rack/app/middlewares/hooks/base"
2
3
  require "rack/app/middlewares/hooks/before"
3
4
  require "rack/app/middlewares/hooks/after"
4
5
  end
@@ -1,14 +1,7 @@
1
- class Rack::App::Middlewares::Hooks::After
2
-
3
- def initialize(app, hook_block)
4
- @app = app
5
- @hook_block = hook_block
6
- end
7
-
1
+ class Rack::App::Middlewares::Hooks::After < Rack::App::Middlewares::Hooks::Base
8
2
  def call(env)
9
3
  response = @app.call(env)
10
- env[Rack::App::Constants::ENV::REQUEST_HANDLER].instance_exec(&@hook_block)
11
- return response
4
+
5
+ return execute_hook(env) || response
12
6
  end
13
-
14
7
  end
@@ -0,0 +1,21 @@
1
+ class Rack::App::Middlewares::Hooks::Base
2
+
3
+ def initialize(app, hook_block)
4
+ @app = app
5
+ @hook_block = hook_block
6
+ end
7
+
8
+ def call(env)
9
+ raise(NotImplementedError)
10
+ end
11
+
12
+ protected
13
+
14
+ def execute_hook(env)
15
+ catch :rack_response do
16
+ env[Rack::App::Constants::ENV::REQUEST_HANDLER].instance_exec(&@hook_block)
17
+ nil
18
+ end
19
+ end
20
+
21
+ end
@@ -1,13 +1,5 @@
1
- class Rack::App::Middlewares::Hooks::Before
2
-
3
- def initialize(app, hook_block)
4
- @app = app
5
- @hook_block = hook_block
6
- end
7
-
1
+ class Rack::App::Middlewares::Hooks::Before < Rack::App::Middlewares::Hooks::Base
8
2
  def call(env)
9
- env[Rack::App::Constants::ENV::REQUEST_HANDLER].instance_exec(&@hook_block)
10
- @app.call(env)
3
+ execute_hook(env) || @app.call(env)
11
4
  end
12
-
13
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.1
4
+ version: 5.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,6 +105,7 @@ files:
105
105
  - lib/rack/app/cli/fetcher/server.rb
106
106
  - lib/rack/app/cli/runner.rb
107
107
  - lib/rack/app/constants.rb
108
+ - lib/rack/app/constants/http_status_codes.rb
108
109
  - lib/rack/app/endpoint.rb
109
110
  - lib/rack/app/endpoint/builder.rb
110
111
  - lib/rack/app/endpoint/config.rb
@@ -114,8 +115,9 @@ files:
114
115
  - lib/rack/app/file_server.rb
115
116
  - lib/rack/app/instance_methods.rb
116
117
  - lib/rack/app/instance_methods/core.rb
117
- - lib/rack/app/instance_methods/http_control.rb
118
+ - lib/rack/app/instance_methods/http_status.rb
118
119
  - lib/rack/app/instance_methods/payload.rb
120
+ - lib/rack/app/instance_methods/redirect_to.rb
119
121
  - lib/rack/app/instance_methods/serve_file.rb
120
122
  - lib/rack/app/instance_methods/streaming.rb
121
123
  - lib/rack/app/middlewares.rb
@@ -126,6 +128,7 @@ files:
126
128
  - lib/rack/app/middlewares/header_setter.rb
127
129
  - lib/rack/app/middlewares/hooks.rb
128
130
  - lib/rack/app/middlewares/hooks/after.rb
131
+ - lib/rack/app/middlewares/hooks/base.rb
129
132
  - lib/rack/app/middlewares/hooks/before.rb
130
133
  - lib/rack/app/middlewares/params.rb
131
134
  - lib/rack/app/middlewares/params/definition.rb