waitress-core 0.4.2 → 0.5.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: 54fb87588d72df10b89f0ec92115c35284ba4d16
4
- data.tar.gz: 0cddde327a2e16e81af8ffdaffb691ad73306c76
3
+ metadata.gz: 904a18272ce3e1f837cb26e024248caaf9da1b3e
4
+ data.tar.gz: dbdbdcafbf43cee59d9a84aa0d0aeab759d6b731
5
5
  SHA512:
6
- metadata.gz: cc0c61ad8c0ae667b8ef0fb4804ba0293a8540941b0e31bcd42da75006c0287f248aef460ac4e6360d165d66dec245cc9768f98b48059015a011f9d109996c21
7
- data.tar.gz: aa03ee737f109dde2c9fe857b80ca0bd7f4ff030328749ecf8ac6e20fee6cd3a846b8bef852ba266cc3c624f0702d27f6d515e02e225829b4f7af97976af021d
6
+ metadata.gz: f403802ef5b0baff1a4c5cd3d54d9dc90c435d77e765fd770d7e44e774c0c86dcacd517a85022097c3cb1354e7b52523fc2fadc313958a670a2a4e7cb05ebe8b
7
+ data.tar.gz: ef03ff5d5d1fe612e44cceda6db4df092784c140ea2ba1b968c19351bc3a7e76fb264ed32159d5a170e2b7dd8c680e38f5a263be10f9adcd3b809d89e5c7115e
@@ -14,6 +14,7 @@ require 'waitress/handlers/handler'
14
14
  require 'waitress/handlers/dirhandler'
15
15
  require 'waitress/handlers/handler404'
16
16
  require 'waitress/handlers/libhandler'
17
+ require 'waitress/handlers/handler500'
17
18
  require 'waitress/chef'
18
19
  require 'waitress/evalbind'
19
20
  require 'waitress/restful/restbuilder'
@@ -29,6 +29,7 @@ module Waitress
29
29
  conf.hosts.each { |h| s << h }
30
30
  s.set_processes conf.processes
31
31
  s.ports *conf.ports
32
+ s.internal_error conf.internal_error
32
33
  s
33
34
  end
34
35
  puts "Waitress Configuration Complete"
@@ -84,11 +85,13 @@ module Waitress
84
85
  attr_accessor :hosts
85
86
  attr_accessor :ports
86
87
  attr_accessor :processes
88
+ attr_accessor :internal_error
87
89
 
88
90
  def initialize configure, *ports
89
91
  @ports = *ports
90
92
  @hosts = []
91
93
  @configure = configure
94
+ @internal_error = false
92
95
 
93
96
  @processes = 5
94
97
  @processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
@@ -116,6 +119,11 @@ module Waitress
116
119
  def less_watch time
117
120
  Waitress::LESSWatcher.set_time time
118
121
  end
122
+
123
+ # Set to true to enable 500 error backtraces in the browser
124
+ def detailed_500 enabled
125
+ @internal_error = enabled
126
+ end
119
127
 
120
128
  def to_s
121
129
  m = lambda { |a,x| x.nil? ? "" : "\r\n#{a}=#{x.inspect}" }
@@ -0,0 +1,28 @@
1
+ module Waitress
2
+
3
+ # The 500 Handler is a simple handler which is triggered when the server encounters an error
4
+ # in the serving of a request. If possible, the handler will alert the client of an internal
5
+ # server error, and if applicable, will display a stacktrace. Stacktraces may be disabled
6
+ # in the server configuration.
7
+ class Handler500
8
+ def self.trigger client, server, error, backtrace
9
+ begin
10
+ client.write "HTTP/1.1 500 Internal Server Error\r\n"
11
+ client.write "Content-Type: text/html\r\n"
12
+ client.write "\r\n"
13
+ client.write "<center> <h1> 500 </h1> <h2> Internal Server Error </h2>"
14
+
15
+ if backtrace
16
+ client.write "<h3> Error Backtrace: </h3>"
17
+ client.write "<div style='text-align: left; width: 50%'>"
18
+ client.write "<p> #{error.backtrace.join '<br>'} </p> </div>"
19
+ end
20
+
21
+ client.write "<hr /> <h5> Waitress HTTP Server Version #{Waitress::VERSION} </h5> </center>"
22
+ client.close
23
+ rescue => e
24
+ # Do nothing, it's a lost cause
25
+ end
26
+ end
27
+ end
28
+ end
@@ -21,6 +21,7 @@ module Waitress
21
21
  @ports = ports
22
22
  @processes = 5
23
23
  @processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
24
+ @backtrace_500 = false
24
25
  @running_processes = []
25
26
  end
26
27
 
@@ -68,6 +69,11 @@ module Waitress
68
69
  def read_io io
69
70
  handle_client io
70
71
  end
72
+
73
+ # Set to true to enable clients to view the 500 error backtrace
74
+ def internal_error enabled
75
+ @backtrace_500 = enabled
76
+ end
71
77
 
72
78
  :private
73
79
  def launch_port port
@@ -123,8 +129,9 @@ module Waitress
123
129
  rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL, Errno::EBADF
124
130
  client_socket.close rescue nil
125
131
  rescue => e
126
- puts "Client Error: #{e}"
127
- puts e.backtrace
132
+ # puts "Client Error: #{e}"
133
+ # puts e.backtrace
134
+ Handler500.trigger client_socket, self, e, @backtrace_500
128
135
  end
129
136
  client_socket.close rescue nil
130
137
  end
@@ -1,3 +1,3 @@
1
1
  module Waitress
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waitress-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaci Brunning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-11 00:00:00.000000000 Z
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -194,6 +194,7 @@ files:
194
194
  - lib/waitress/handlers/dirhandler.rb
195
195
  - lib/waitress/handlers/handler.rb
196
196
  - lib/waitress/handlers/handler404.rb
197
+ - lib/waitress/handlers/handler500.rb
197
198
  - lib/waitress/handlers/libhandler.rb
198
199
  - lib/waitress/kernel.rb
199
200
  - lib/waitress/parse/query.rb