bees 0.1

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.
@@ -0,0 +1,21 @@
1
+ (MIT License)
2
+
3
+ Copyright (c) 2013 Adam Prescott <adam@aprescott.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # 500 The Bees They're In My Eyes
2
+
3
+ Replace the 500 HTTP status message with [`The Bees They're In My Eyes`](https://github.com/codahale/codahale.com/blob/036912e018da23cabd19f1062a0915b2f9a8d114/_posts/2010-10-07-you-cant-sacrifice-partition-tolerance.md#on-availability) in all your favourite web servers:
4
+
5
+ * Rack
6
+ * Puma
7
+ * Thin
8
+ * Webrick
9
+ * CGI
10
+
11
+ ## Build the hive
12
+
13
+ ```ruby
14
+ require "rack/bees"
15
+ Rack::Handler::Thin.run lambda { |env| [500, { "Content-Type" => "text/html" }, ["Hello world!"]] }, :Port => 5909
16
+ ```
17
+
18
+ ## Shake the hive
19
+
20
+ ```
21
+ $ curl -sI localhost:5909 | head -n 1
22
+ HTTP/1.1 500 The Bees They're In My Eyes
23
+ ```
24
+
25
+ ## Hives
26
+
27
+ ```ruby
28
+ # rack bees (also covers Puma and others that rely on Rack's status info)
29
+ require "rack/bees"
30
+
31
+ # thin bees
32
+ require "thin/bees"
33
+
34
+ # webrick bees
35
+ require "webrick/bees"
36
+
37
+ # cgi bees
38
+ require "cgi/bees"
39
+
40
+ # any of the above that'll successfully load
41
+ require "bees"
42
+ # Failed to require rack/bees -- skipping
43
+ # Failed to require thin/bees -- skipping
44
+ # Failed to require cgi/bees -- skipping
45
+
46
+ WEBrick::HTTPStatus::StatusMessage[500]
47
+ #=> "The Bees They're In My Eyes"
48
+ ```
49
+
50
+ # My server needs bees too!
51
+
52
+ Want bees in your favourite web server? [Open an issue or a pull request](https://github.com/aprescott/bees.rb)!
53
+
54
+ # License
55
+
56
+ Copyright Adam Prescott. Released under the MIT license. Any contributions will be assumed by default to be under the same terms.
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "bees"
3
+ s.version = "0.1"
4
+ s.authors = ["Adam Prescott"]
5
+ s.email = ["adam@aprescott.com"]
6
+ s.homepage = "https://github.com/aprescott/bees.rb"
7
+ s.summary = "500 The Bees They're In My Eyes"
8
+ s.description = "Put some bees in your web server."
9
+ s.files = Dir["lib/**/*"] + %w[bees.gemspec LICENSE.mit README.md]
10
+ s.require_path = "lib"
11
+ end
@@ -0,0 +1,23 @@
1
+ require "hive"
2
+
3
+ load_attempts = [
4
+ "rack/bees",
5
+ "thin/bees",
6
+ "webrick/bees",
7
+ "cgi/bees"
8
+ ].map do |k|
9
+ begin
10
+ require k
11
+ rescue Bees::HandlerLoadError => e
12
+ puts "Failed to require #{k} -- skipping"
13
+
14
+ # return nil on failure
15
+ nil
16
+ end
17
+ end
18
+
19
+ # nil load attempt value = failed to load
20
+ successful_loads = load_attempts.compact
21
+
22
+ # if we couldn't load anything at all one, bail
23
+ raise LoadError.new("Failed to override any handlers") unless successful_loads.length > 0
@@ -0,0 +1,5 @@
1
+ require "hive"
2
+
3
+ Bees.attempt_load("cgi") do
4
+ CGI::HTTP_STATUS["SERVER_ERROR"] = "500 #{Bees::STATUS_MESSAGE}"
5
+ end
@@ -0,0 +1,38 @@
1
+ module Bees
2
+ STATUS_MESSAGE = "The Bees They're In My Eyes"
3
+
4
+ # custom error we can detect an inner require failure specifically
5
+ # instead of an outer require failure
6
+ class HandlerLoadError < NameError; end
7
+
8
+ # Attempt to run the HTTP status code override in the given
9
+ # block. If the first try fails, require gem_name (might not
10
+ # actually be a gem), and try yielding again.
11
+ #
12
+ # This allows us to do, e.g.,
13
+ #
14
+ # require "rack/bees"
15
+ #
16
+ # as equivalent to
17
+ #
18
+ # require "rack"
19
+ # require "rack/bees"
20
+ #
21
+ # If gem_name can't be require()d, a LoadError will be raised
22
+ # as usual.
23
+ def self.attempt_load(gem_name)
24
+ begin
25
+ skip_retry = false
26
+ begin
27
+ yield
28
+ rescue NameError
29
+ return if skip_retry
30
+ require gem_name
31
+ skip_retry = true
32
+ retry
33
+ end
34
+ rescue LoadError
35
+ raise HandlerLoadError.new("Failed to load handler")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ require "hive"
2
+
3
+ Bees.attempt_load("rack") do
4
+ # Note that this leaves Rack::Utils::SYMBOL_TO_STATUS_CODE
5
+ # untouched, since we're overriding, so :the_bees_theyre_in_my_eyes
6
+ # isn't usable. Which is desired behaviour, otherwise
7
+ # :internal_server_error would be unusable!
8
+ Rack::Utils::HTTP_STATUS_CODES[500] = Bees::STATUS_MESSAGE
9
+ end
@@ -0,0 +1,5 @@
1
+ require "hive"
2
+
3
+ Bees.attempt_load("thin") do
4
+ Thin::HTTP_STATUS_CODES[500] = Bees::STATUS_MESSAGE
5
+ end
@@ -0,0 +1,5 @@
1
+ require "hive"
2
+
3
+ Bees.attempt_load("webrick") do
4
+ WEBrick::HTTPStatus::StatusMessage[500] = Bees::STATUS
5
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bees
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Prescott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Put some bees in your web server.
15
+ email:
16
+ - adam@aprescott.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/bees.rb
22
+ - lib/cgi/bees.rb
23
+ - lib/hive.rb
24
+ - lib/rack/bees.rb
25
+ - lib/thin/bees.rb
26
+ - lib/webrick/bees.rb
27
+ - bees.gemspec
28
+ - LICENSE.mit
29
+ - README.md
30
+ homepage: https://github.com/aprescott/bees.rb
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: 500 The Bees They're In My Eyes
54
+ test_files: []