waitress-core 0.2.4 → 0.3.0

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/LICENSE +21 -21
  4. data/Rakefile +17 -17
  5. data/bin/waitress +22 -22
  6. data/ext/Thanks.md +1 -1
  7. data/ext/waitress_http11/ext_help.h +15 -15
  8. data/ext/waitress_http11/extconf.rb +6 -6
  9. data/ext/waitress_http11/http11.c +532 -532
  10. data/ext/waitress_http11/http11_parser.c +1216 -1216
  11. data/ext/waitress_http11/http11_parser.h +49 -49
  12. data/ext/waitress_http11/http11_parser.java.rl +171 -171
  13. data/ext/waitress_http11/http11_parser.rl +165 -165
  14. data/ext/waitress_http11/http11_parser_common.rl +55 -55
  15. data/ext/waitress_http11/http11_wrb_parser.h +91 -91
  16. data/lib/waitress.rb +100 -99
  17. data/lib/waitress/chef.rb +113 -113
  18. data/lib/waitress/configure.rb +127 -121
  19. data/lib/waitress/evalbind.rb +9 -9
  20. data/lib/waitress/handlers/dirhandler.rb +39 -39
  21. data/lib/waitress/handlers/handler.rb +57 -57
  22. data/lib/waitress/handlers/handler404.rb +25 -25
  23. data/lib/waitress/handlers/libhandler.rb +135 -58
  24. data/lib/waitress/kernel.rb +189 -189
  25. data/lib/waitress/parse/query.rb +60 -60
  26. data/lib/waitress/request.rb +45 -45
  27. data/lib/waitress/resources/default_config.rb +52 -52
  28. data/lib/waitress/resources/default_less.yml +7 -0
  29. data/lib/waitress/resources/http/404.html +18 -18
  30. data/lib/waitress/resources/http/css/hack.css +37 -37
  31. data/lib/waitress/resources/http/css/waitress.css +57 -57
  32. data/lib/waitress/resources/http/fonts/eot/latin/hack-bold-latin-webfont.eot +0 -0
  33. data/lib/waitress/resources/http/fonts/eot/latin/hack-bolditalic-latin-webfont.eot +0 -0
  34. data/lib/waitress/resources/http/fonts/eot/latin/hack-italic-latin-webfont.eot +0 -0
  35. data/lib/waitress/resources/http/fonts/eot/latin/hack-regular-latin-webfont.eot +0 -0
  36. data/lib/waitress/resources/http/fonts/svg/latin/hack-bold-latin-webfont.svg +240 -240
  37. data/lib/waitress/resources/http/fonts/svg/latin/hack-bolditalic-latin-webfont.svg +240 -240
  38. data/lib/waitress/resources/http/fonts/svg/latin/hack-italic-latin-webfont.svg +240 -240
  39. data/lib/waitress/resources/http/fonts/svg/latin/hack-regular-latin-webfont.svg +240 -240
  40. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bold-latin-webfont.ttf +0 -0
  41. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bolditalic-latin-webfont.ttf +0 -0
  42. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-italic-latin-webfont.ttf +0 -0
  43. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-regular-latin-webfont.ttf +0 -0
  44. data/lib/waitress/resources/http/fonts/woff/latin/hack-bold-latin-webfont.woff +0 -0
  45. data/lib/waitress/resources/http/fonts/woff/latin/hack-bolditalic-latin-webfont.woff +0 -0
  46. data/lib/waitress/resources/http/fonts/woff/latin/hack-italic-latin-webfont.woff +0 -0
  47. data/lib/waitress/resources/http/fonts/woff/latin/hack-regular-latin-webfont.woff +0 -0
  48. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bold-latin-webfont.woff2 +0 -0
  49. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bolditalic-latin-webfont.woff2 +0 -0
  50. data/lib/waitress/resources/http/fonts/woff2/latin/hack-italic-latin-webfont.woff2 +0 -0
  51. data/lib/waitress/resources/http/fonts/woff2/latin/hack-regular-latin-webfont.woff2 +0 -0
  52. data/lib/waitress/resources/http/img/404.png +0 -0
  53. data/lib/waitress/resources/http/index.html +15 -15
  54. data/lib/waitress/response.rb +105 -105
  55. data/lib/waitress/server.rb +160 -160
  56. data/lib/waitress/util/less_watcher.rb +56 -0
  57. data/lib/waitress/{util.rb → util/util.rb} +707 -707
  58. data/lib/waitress/version.rb +3 -3
  59. data/lib/waitress/vhost.rb +229 -227
  60. data/lib/waitress_http11.so +0 -0
  61. data/waitress-core.gemspec +32 -29
  62. metadata +48 -4
  63. data/lib/waitress_http11.bundle +0 -0
data/lib/waitress/chef.rb CHANGED
@@ -1,113 +1,113 @@
1
- module Waitress
2
-
3
- # The chef class handles the cooking of responses, by serving errors and files
4
- # from the Filesystem, as well as providing a system for including files within
5
- # handlers and .wrb files. This class handles most loading from Filesystems
6
- # and serving of the body of a response.
7
- class Chef
8
-
9
- HANDLERS = {
10
- 404 => Handler404.new
11
- }
12
-
13
- # Get the waitress resources directory, containing templates and the default
14
- # http assets of waitress
15
- def self.resources
16
- File.expand_path "../resources", __FILE__
17
- end
18
-
19
- # Get the waitress HTTP assets directory, containing the default index, 404
20
- # and styles resources.
21
- def self.resources_http
22
- File.join(resources, "http")
23
- end
24
-
25
- # Set the response to use an error page with the given error code (usually 404)
26
- def self.error code, request, response, client, vhost
27
- HANDLERS[code].serve!(request, response, client, vhost)
28
- end
29
-
30
- # Serve a file from the Filesystem, automatically handling based on whether the
31
- # file is dynamic or static. This will set the body io and any required
32
- # headers on the reponse object.
33
- def self.serve_file request, response, client, vhost, file
34
- if File.extname(file) == ".wrb" || File.extname(file) == ".rb"
35
- response.mime ".html"
36
- include_absfile File.expand_path(file)
37
- else
38
- response.mime File.extname(file)
39
- response.body_io File.open(file, "r")
40
- end
41
- end
42
-
43
- # Include a file from the VHost loadpath in the current running instance.
44
- # Params:
45
- # +filename+:: The filename of the file, relative to the load path of the VHost.
46
- def self.include_file filename
47
- lp = $VHOST.load_path
48
- target = nil
49
- lp.each do |path|
50
- fl = File.join(path, filename)
51
- ext = ["", ".rb", ".wrb"]
52
- ext.each do |e|
53
- flnew = "#{fl}#{e}"
54
- target = flnew if File.exist?(flnew)
55
- end
56
- end
57
-
58
- raise LoadError.new("Include does not exist in Load Path: #{target}") if target.nil?
59
- include_absfile target
60
- end
61
-
62
- # Include a file from anywhere in the filesystem (absolute) in the current running
63
- # instance. This will load the file's content and, if dynamic, evaluate it to the
64
- # current response.
65
- # Params:
66
- # +target+:: The target file, given in absolute path form.
67
- def self.include_absfile target
68
- ext = File.extname target
69
- bind = Waitress::EvalBindings.new
70
- if ext == ".wrb"
71
- Waitress::WRBParser.parse!(File.read(target), $RESPONSE.body_io) do |txt, lino|
72
- eval(txt, bind.context, target, lino) # For some reason, rb_f_eval is not exposed to ruby.h
73
- end
74
- elsif ext == ".rb"
75
- require target
76
- else
77
- echo File.read(target)
78
- end
79
- end
80
-
81
- # Find a file to serve. This is used by the DirHandler
82
- # to automatically include an index file if it exists under the
83
- # requested directory, automatically add the .wrb or .html file extension
84
- # for paths without the extension, etc. A hash containing the result (ok / notfound)
85
- # and the new filepath will be given.
86
- def self.find_file abspath
87
- ret = {}
88
- if File.exist?(abspath)
89
- if File.directory?(abspath)
90
- wrb = File.join(abspath, "index.wrb")
91
- html = File.join(abspath, "index.html")
92
- if File.exist?(wrb)
93
- ret = { :result => :ok, :file => wrb }
94
- elsif File.exist?(html)
95
- ret = { :result => :ok, :file => html }
96
- else
97
- ret = { :result => :dir, :file => abspath }
98
- end
99
- else
100
- ret = { :result => :ok, :file => abspath }
101
- end
102
- elsif File.exist?("#{abspath}.html")
103
- ret = { :result => :ok, :file => "#{abspath}.html" }
104
- elsif File.exist?("#{abspath}.wrb")
105
- ret = { :result => :ok, :file => "#{abspath}.wrb" }
106
- else
107
- ret = { :result => :notfound }
108
- end
109
- ret
110
- end
111
-
112
- end
113
- end
1
+ module Waitress
2
+
3
+ # The chef class handles the cooking of responses, by serving errors and files
4
+ # from the Filesystem, as well as providing a system for including files within
5
+ # handlers and .wrb files. This class handles most loading from Filesystems
6
+ # and serving of the body of a response.
7
+ class Chef
8
+
9
+ HANDLERS = {
10
+ 404 => Handler404.new
11
+ }
12
+
13
+ # Get the waitress resources directory, containing templates and the default
14
+ # http assets of waitress
15
+ def self.resources
16
+ File.expand_path "../resources", __FILE__
17
+ end
18
+
19
+ # Get the waitress HTTP assets directory, containing the default index, 404
20
+ # and styles resources.
21
+ def self.resources_http
22
+ File.join(resources, "http")
23
+ end
24
+
25
+ # Set the response to use an error page with the given error code (usually 404)
26
+ def self.error code, request, response, client, vhost
27
+ HANDLERS[code].serve!(request, response, client, vhost)
28
+ end
29
+
30
+ # Serve a file from the Filesystem, automatically handling based on whether the
31
+ # file is dynamic or static. This will set the body io and any required
32
+ # headers on the reponse object.
33
+ def self.serve_file request, response, client, vhost, file
34
+ if File.extname(file) == ".wrb" || File.extname(file) == ".rb"
35
+ response.mime ".html"
36
+ include_absfile File.expand_path(file)
37
+ else
38
+ response.mime File.extname(file)
39
+ response.body_io File.open(file, "r")
40
+ end
41
+ end
42
+
43
+ # Include a file from the VHost loadpath in the current running instance.
44
+ # Params:
45
+ # +filename+:: The filename of the file, relative to the load path of the VHost.
46
+ def self.include_file filename
47
+ lp = $VHOST.load_path
48
+ target = nil
49
+ lp.each do |path|
50
+ fl = File.join(path, filename)
51
+ ext = ["", ".rb", ".wrb"]
52
+ ext.each do |e|
53
+ flnew = "#{fl}#{e}"
54
+ target = flnew if File.exist?(flnew)
55
+ end
56
+ end
57
+
58
+ raise LoadError.new("Include does not exist in Load Path: #{target}") if target.nil?
59
+ include_absfile target
60
+ end
61
+
62
+ # Include a file from anywhere in the filesystem (absolute) in the current running
63
+ # instance. This will load the file's content and, if dynamic, evaluate it to the
64
+ # current response.
65
+ # Params:
66
+ # +target+:: The target file, given in absolute path form.
67
+ def self.include_absfile target
68
+ ext = File.extname target
69
+ bind = Waitress::EvalBindings.new
70
+ if ext == ".wrb"
71
+ Waitress::WRBParser.parse!(File.read(target), $RESPONSE.body_io) do |txt, lino|
72
+ eval(txt, bind.context, target, lino) # For some reason, rb_f_eval is not exposed to ruby.h
73
+ end
74
+ elsif ext == ".rb"
75
+ require target
76
+ else
77
+ echo File.read(target)
78
+ end
79
+ end
80
+
81
+ # Find a file to serve. This is used by the DirHandler
82
+ # to automatically include an index file if it exists under the
83
+ # requested directory, automatically add the .wrb or .html file extension
84
+ # for paths without the extension, etc. A hash containing the result (ok / notfound)
85
+ # and the new filepath will be given.
86
+ def self.find_file abspath
87
+ ret = {}
88
+ if File.exist?(abspath)
89
+ if File.directory?(abspath)
90
+ wrb = File.join(abspath, "index.wrb")
91
+ html = File.join(abspath, "index.html")
92
+ if File.exist?(wrb)
93
+ ret = { :result => :ok, :file => wrb }
94
+ elsif File.exist?(html)
95
+ ret = { :result => :ok, :file => html }
96
+ else
97
+ ret = { :result => :dir, :file => abspath }
98
+ end
99
+ else
100
+ ret = { :result => :ok, :file => abspath }
101
+ end
102
+ elsif File.exist?("#{abspath}.html")
103
+ ret = { :result => :ok, :file => "#{abspath}.html" }
104
+ elsif File.exist?("#{abspath}.wrb")
105
+ ret = { :result => :ok, :file => "#{abspath}.wrb" }
106
+ else
107
+ ret = { :result => :notfound }
108
+ end
109
+ ret
110
+ end
111
+
112
+ end
113
+ end
@@ -1,121 +1,127 @@
1
- module Waitress
2
-
3
- # The Configure Class is used to load Waitress configurations from the filesystem,
4
- # usually used in the config.rb file.
5
- class Configure
6
-
7
- # Endpoint for Waitress.configure!
8
- def self.configure! *args, &block
9
- raise "Using 'configure!' outside of file target" if @@configure_target.nil?
10
- @@configure_target.read_configure *args, &block
11
- end
12
-
13
- def self.config_target o
14
- @@configure_target = o
15
- end
16
-
17
- attr_accessor :servers
18
- attr_accessor :root
19
-
20
- def initialize root
21
- @root = root
22
- @configurations = []
23
- generate_configs
24
-
25
- load_cfg
26
-
27
- @servers = @configurations.map do |conf|
28
- s = Waitress::HttpServer.new
29
- conf.hosts.each { |h| s << h }
30
- s.set_processes conf.processes
31
- s.ports *conf.ports
32
- s
33
- end
34
- puts "Waitress Configuration Complete"
35
- puts "Servers Started on Ports: "
36
- @servers.each do |x|
37
- puts "\t#{x.ports.join ", "}"
38
- end
39
- end
40
-
41
- # Run all servers in this configuration
42
- def run
43
- @servers.each { |s| s.run }
44
- end
45
-
46
- # Join all the server threads in this configuration
47
- def join
48
- @servers.each { |s| s.join }
49
- end
50
-
51
- # Read the configuration object
52
- def read_configure *args, &block
53
- config = Configuration.new self, *args
54
- block.call(config)
55
- @configurations << config
56
- end
57
-
58
- # Generate the configuration file if it doesn't already exist.
59
- def generate_configs
60
- FileUtils.mkdir_p(@root) unless File.exist?(@root)
61
- raise "File #{@root} is not a directory!" unless File.directory?(@root)
62
- @config = File.join(@root, "config.rb")
63
- unless File.exist?(@config)
64
- c = File.read(File.join(Waitress::Chef.resources, "default_config.rb"))
65
- File.write(@config, c)
66
- end
67
- end
68
-
69
- # Load the config.rb file
70
- def load_cfg
71
- Waitress::Configure.config_target self
72
- path = File.absolute_path(@config)
73
- require path
74
- Waitress::Configure.config_target nil
75
- end
76
-
77
- end
78
-
79
- # The Configuration Class is the object that contains a configuration
80
- # of a single server instance, hosting all the methods provided by
81
- # Waitress.configure!
82
- class Configuration
83
-
84
- attr_accessor :hosts
85
- attr_accessor :ports
86
- attr_accessor :processes
87
-
88
- def initialize configure, *ports
89
- @ports = *ports
90
- @hosts = []
91
- @configure = configure
92
-
93
- @processes = 5
94
- @processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
95
- end
96
-
97
- # Create a new VirtualHost with the given regex, priority, and configure it
98
- # inside of its own block.
99
- def host regex, priority=50, &block
100
- host = Waitress::Vhost.new regex, priority
101
- host.set_configure @configure
102
- block.call(host)
103
- @hosts << host
104
- host
105
- end
106
-
107
- # Over all the registered VHosts, call this method. Use this to configure
108
- # a similar setting for all vhosts at once instead of duplicating code
109
- # across all of them.
110
- def all_hosts &block
111
- @hosts.each { |h| block.call(h) }
112
- end
113
-
114
- def to_s
115
- m = lambda { |a,x| x.nil? ? "" : "\r\n#{a}=#{x.inspect}" }
116
- "#<#{self.class} #{m.call('ports', @ports)} #{m.call('hosts', @hosts)}>"
117
- end
118
-
119
- end
120
-
121
- end
1
+ module Waitress
2
+
3
+ # The Configure Class is used to load Waitress configurations from the filesystem,
4
+ # usually used in the config.rb file.
5
+ class Configure
6
+
7
+ # Endpoint for Waitress.configure!
8
+ def self.configure! *args, &block
9
+ raise "Using 'configure!' outside of file target" if @@configure_target.nil?
10
+ @@configure_target.read_configure *args, &block
11
+ end
12
+
13
+ def self.config_target o
14
+ @@configure_target = o
15
+ end
16
+
17
+ attr_accessor :servers
18
+ attr_accessor :root
19
+
20
+ def initialize root
21
+ @root = root
22
+ @configurations = []
23
+ generate_configs
24
+
25
+ load_cfg
26
+
27
+ @servers = @configurations.map do |conf|
28
+ s = Waitress::HttpServer.new
29
+ conf.hosts.each { |h| s << h }
30
+ s.set_processes conf.processes
31
+ s.ports *conf.ports
32
+ s
33
+ end
34
+ puts "Waitress Configuration Complete"
35
+ puts "Servers Started on Ports: "
36
+ @servers.each do |x|
37
+ puts "\t#{x.ports.join ", "}"
38
+ end
39
+ end
40
+
41
+ # Run all servers in this configuration
42
+ def run
43
+ @servers.each { |s| s.run }
44
+ end
45
+
46
+ # Join all the server threads in this configuration
47
+ def join
48
+ @servers.each { |s| s.join }
49
+ end
50
+
51
+ # Read the configuration object
52
+ def read_configure *args, &block
53
+ config = Configuration.new self, *args
54
+ block.call(config)
55
+ @configurations << config
56
+ end
57
+
58
+ # Generate the configuration file if it doesn't already exist.
59
+ def generate_configs
60
+ FileUtils.mkdir_p(@root) unless File.exist?(@root)
61
+ raise "File #{@root} is not a directory!" unless File.directory?(@root)
62
+ @config = File.join(@root, "config.rb")
63
+ unless File.exist?(@config)
64
+ c = File.read(File.join(Waitress::Chef.resources, "default_config.rb"))
65
+ File.write(@config, c)
66
+ end
67
+ end
68
+
69
+ # Load the config.rb file
70
+ def load_cfg
71
+ Waitress::Configure.config_target self
72
+ path = File.absolute_path(@config)
73
+ require path
74
+ Waitress::Configure.config_target nil
75
+ end
76
+
77
+ end
78
+
79
+ # The Configuration Class is the object that contains a configuration
80
+ # of a single server instance, hosting all the methods provided by
81
+ # Waitress.configure!
82
+ class Configuration
83
+
84
+ attr_accessor :hosts
85
+ attr_accessor :ports
86
+ attr_accessor :processes
87
+
88
+ def initialize configure, *ports
89
+ @ports = *ports
90
+ @hosts = []
91
+ @configure = configure
92
+
93
+ @processes = 5
94
+ @processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
95
+ end
96
+
97
+ # Create a new VirtualHost with the given regex, priority, and configure it
98
+ # inside of its own block.
99
+ def host regex, priority=50, &block
100
+ host = Waitress::Vhost.new regex, priority
101
+ host.set_configure @configure
102
+ block.call(host)
103
+ @hosts << host
104
+ host
105
+ end
106
+
107
+ # Over all the registered VHosts, call this method. Use this to configure
108
+ # a similar setting for all vhosts at once instead of duplicating code
109
+ # across all of them.
110
+ def all_hosts &block
111
+ @hosts.each { |h| block.call(h) }
112
+ end
113
+
114
+ # Set the watch period for the LESS Watcher, i.e. how long to sleep before
115
+ # checking LESS files for an update and recompile
116
+ def less_watch time
117
+ Waitress::LESSWatcher.set_time time
118
+ end
119
+
120
+ def to_s
121
+ m = lambda { |a,x| x.nil? ? "" : "\r\n#{a}=#{x.inspect}" }
122
+ "#<#{self.class} #{m.call('ports', @ports)} #{m.call('hosts', @hosts)}>"
123
+ end
124
+
125
+ end
126
+
127
+ end