waitress-core 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/LICENSE +21 -21
  4. data/Rakefile +13 -4
  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 +83 -83
  16. data/lib/waitress/chef.rb +110 -110
  17. data/lib/waitress/configure.rb +116 -116
  18. data/lib/waitress/handlers/dirhandler.rb +39 -39
  19. data/lib/waitress/handlers/handler.rb +57 -57
  20. data/lib/waitress/handlers/handler404.rb +25 -25
  21. data/lib/waitress/handlers/libhandler.rb +58 -58
  22. data/lib/waitress/kernel.rb +182 -182
  23. data/lib/waitress/parse/query.rb +60 -60
  24. data/lib/waitress/request.rb +45 -45
  25. data/lib/waitress/resources/default_config.rb +52 -52
  26. data/lib/waitress/resources/http/404.html +18 -18
  27. data/lib/waitress/resources/http/css/hack.css +37 -37
  28. data/lib/waitress/resources/http/css/waitress.css +57 -57
  29. data/lib/waitress/resources/http/fonts/eot/latin/hack-bold-latin-webfont.eot +0 -0
  30. data/lib/waitress/resources/http/fonts/eot/latin/hack-bolditalic-latin-webfont.eot +0 -0
  31. data/lib/waitress/resources/http/fonts/eot/latin/hack-italic-latin-webfont.eot +0 -0
  32. data/lib/waitress/resources/http/fonts/eot/latin/hack-regular-latin-webfont.eot +0 -0
  33. data/lib/waitress/resources/http/fonts/svg/latin/hack-bold-latin-webfont.svg +240 -240
  34. data/lib/waitress/resources/http/fonts/svg/latin/hack-bolditalic-latin-webfont.svg +240 -240
  35. data/lib/waitress/resources/http/fonts/svg/latin/hack-italic-latin-webfont.svg +240 -240
  36. data/lib/waitress/resources/http/fonts/svg/latin/hack-regular-latin-webfont.svg +240 -240
  37. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bold-latin-webfont.ttf +0 -0
  38. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bolditalic-latin-webfont.ttf +0 -0
  39. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-italic-latin-webfont.ttf +0 -0
  40. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-regular-latin-webfont.ttf +0 -0
  41. data/lib/waitress/resources/http/fonts/woff/latin/hack-bold-latin-webfont.woff +0 -0
  42. data/lib/waitress/resources/http/fonts/woff/latin/hack-bolditalic-latin-webfont.woff +0 -0
  43. data/lib/waitress/resources/http/fonts/woff/latin/hack-italic-latin-webfont.woff +0 -0
  44. data/lib/waitress/resources/http/fonts/woff/latin/hack-regular-latin-webfont.woff +0 -0
  45. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bold-latin-webfont.woff2 +0 -0
  46. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bolditalic-latin-webfont.woff2 +0 -0
  47. data/lib/waitress/resources/http/fonts/woff2/latin/hack-italic-latin-webfont.woff2 +0 -0
  48. data/lib/waitress/resources/http/fonts/woff2/latin/hack-regular-latin-webfont.woff2 +0 -0
  49. data/lib/waitress/resources/http/img/404.png +0 -0
  50. data/lib/waitress/resources/http/index.html +15 -15
  51. data/lib/waitress/response.rb +104 -104
  52. data/lib/waitress/server.rb +126 -115
  53. data/lib/waitress/util.rb +707 -713
  54. data/lib/waitress/version.rb +3 -3
  55. data/lib/waitress/vhost.rb +217 -217
  56. data/lib/waitress.rb +98 -98
  57. data/lib/waitress_http11.bundle +0 -0
  58. data/waitress-core.gemspec +29 -27
  59. metadata +35 -7
  60. data/lib/waitress_http11.so +0 -0
@@ -1,3 +1,3 @@
1
- module Waitress
2
- VERSION = "0.0.3"
3
- end
1
+ module Waitress
2
+ VERSION = "0.0.4"
3
+ end
@@ -1,217 +1,217 @@
1
- module Waitress
2
- # The VHost class is responsible for the actions of a Virtual Host, that is
3
- # reacting to a certain subdomain and handling the requests that are sent to it.
4
- # The requests are managed through the usage of +Waitress::Handler+ instances.
5
- class Vhost < Array
6
-
7
- attr_accessor :priority
8
- attr_accessor :domain
9
- attr_accessor :load_path
10
-
11
- attr_accessor :combos
12
- attr_accessor :libraries
13
-
14
- # Create a new Virtual Host to manage traffic on a Subdomain (Host header)
15
- # Params:
16
- # +pattern+:: The regex pattern used to match this VHost to subdomain(s)
17
- # +priority+:: The priority of the VHost. If multiple VHosts match the subdomain,
18
- # the VHost with the highest priority will be chosen. Default: 50
19
- def initialize pattern, priority=50
20
- @domain = pattern
21
- @priority = priority
22
- @load_path = []
23
- @libdir = "~/.waitress/www/libs"
24
- @liburi = "libraries"
25
-
26
- @libraries = {}
27
- @combos = {}
28
-
29
- @on_request = []
30
- @after_request = []
31
-
32
- enable_waitress_resources
33
- end
34
-
35
- # Register a listener that will be triggered once a request has been received
36
- # by this VHost, but before it has been passed to a listener or served. Use this
37
- # to modify a request before it is handled.
38
- # The Block should take arguments:
39
- # +request+:: The +Waitress::Request+ object
40
- # +vhost+:: The VirtualHost instance
41
- # +client+:: The Client Socket object
42
- def on_request &block
43
- @on_request << block
44
- end
45
-
46
- # Register a listener that will be triggered once a request has been received
47
- # by this VHost, after it has been handled, but before it is served.
48
- # The Block should take arguments:
49
- # +request+:: The +Waitress::Request+ object
50
- # +response+:: The +Waitress::Response+ object
51
- # +vhost+:: The VirtualHost instance
52
- # +client+:: The Client Socket object
53
- def after_request &block
54
- @after_request << block
55
- end
56
-
57
- # Call this to disable the Waitress Handler (Waitress' default CSS, JS, 404 and Index)
58
- def disable_waitress_resources
59
- @resources = false
60
- end
61
-
62
- # Call this to enable the Waitress Handler (Waitress' default CSS, JS, 404 and Index)
63
- def enable_waitress_resources
64
- @resources = true
65
- end
66
-
67
- # Returns true if the VHost has the Waitress Handler enabled (Waitress' default CSS, JS, 404 and Index)
68
- def resources?
69
- @resources
70
- end
71
-
72
- # Change the default 404 page for the VHost. This should be an absolute file path to your 404 page
73
- # file that you wish to use
74
- def set_404 link
75
- @page_404 = link
76
- end
77
-
78
- # Get the absolute file path for the 404 page to use for this VHost. May be nil.
79
- def get_404
80
- @page_404
81
- end
82
-
83
- # Add a Document Root for this VHost. This document root will contain all of your
84
- # public files that can be served by the vhost.
85
- # Params:
86
- # +dir+:: The directory for the Document Root
87
- # +priority+:: The priority for the directory. If multiple Handlers respond to the target
88
- # URI, the one with the highest priority will be chosen. Default: 50
89
- def root dir, priority=50
90
- self << Waitress::DirHandler.new(File.expand_path(dir), priority)
91
- end
92
-
93
- # Internal
94
- def set_configure conf
95
- @configuration = conf
96
- end
97
-
98
- # Set the directory in which Libraries are contained. Libraries are specially handled by
99
- # waitress to be loaded into .wrb files and handlers. Default: "libs/"
100
- # This file will contain your CSS, JS and any other libraries.
101
- def libdir name
102
- @libdir = File.expand_path(name)
103
- end
104
-
105
- # Change the uri that Libraries should be accessed from. Libraries present in the "libs/"
106
- # directory are served from this URI. This URI is relative to the base "/" uri for the VirtualHost,
107
- # for example, a LibUri of "libraries/" (the default) will be accessed by "your.site/libraries/lib_name"
108
- def liburi name=nil
109
- @liburi = name unless name.nil?
110
- @liburi
111
- end
112
-
113
- # Bind a library to a name. By default, when libraries are found in the css/ and js/ folders of your
114
- # lib directory, they are loaded under the lib name of "filename.type", with type being .css or .js.
115
- # By binding a library, you can give this a different name based on the file found by regular expression,
116
- # for example, binding /jquery/ to "jquery" will match any filenames containing 'jquery', meaning the full
117
- # name of 'jquery-ver.sion' is matched, and can be accessed simply by "jquery"
118
- # Params:
119
- # +pattern+:: The regular expression to check files against. This will match the first file it finds with
120
- # the expression to the library.
121
- # +type+:: The type of file. This should be a symbol of either :js or :css, or any other supported lib types
122
- # +name+:: The new name to reference this library by
123
- # +options+:: Any extra options to use when loading the library (to be used in the future)
124
- def bind_lib pattern, type, name, *options
125
- lib = { :pattern => pattern, :bindtype => type, :options => options}
126
- @libraries[name.to_sym] = lib
127
- end
128
-
129
- # Define a combination of libraries. Calling this method will bind all the libaries listed under one common
130
- # name that can be loaded into .wrb files and handlers using combo(). This is used to load a collection of
131
- # libraries simply and easily without repeating lib() methods.
132
- # Params:
133
- # +name+:: The desired name of the combo
134
- # +targets+:: A list of all the libraries to bind to this combo
135
- def combo name, *targets
136
- @combos[name.to_sym] = targets
137
- targets
138
- end
139
-
140
- # Internal
141
- def parse_libraries
142
- self << Waitress::LibraryHandler.new(@libraries, @libdir, @liburi, self)
143
- end
144
-
145
- # Internal (called on Server Start)
146
- def on_server_start srv
147
- parse_libraries
148
- end
149
-
150
- # Used to define the load path for the VHost. The Load Path defines what files can be
151
- # included from outside of the public web directory, such as database backend or
152
- # authentication. These files are not available to the public, but can be included by
153
- # the .wrb files.
154
- # Params:
155
- # +dir+: The directory to use for the loadpath. If a string is provided, it is added,
156
- # however, if an array is provided, it will override with the array.
157
- def includes dir
158
- if dir.is_a? String
159
- load_path << File.expand_path(dir)
160
- elsif dir.is_a? Array
161
- load_path = dir.map { |x| File.expand_path(x) }
162
- end
163
- end
164
-
165
- # Cancel the current request (don't serve the response)
166
- def cancel_request
167
- @cancelled = true
168
- end
169
-
170
- # Define a rewrite rule. A rewrite rule is used to rewrite a URL's path
171
- # before it is handled. Keep in mind that this does not function for a query string,
172
- # which should instead be handled with the on_request event.
173
- # Params;
174
- # +pattern+:: The pattern to match the URL against
175
- # +newpath+:: The new path to replace the matched pattern with. This can include
176
- # capture groups through the use of \\1 (where 1 is the capture group number)
177
- def rewrite pattern, newpath
178
- on_request do |request, vhost|
179
- request.path = request.path.gsub(pattern, newpath)
180
- end
181
- end
182
-
183
- # Internal (matches requests)
184
- def handle_request request, client
185
- @cancelled = false
186
-
187
- response = Waitress::Response.new
188
-
189
- $REQUEST = request
190
- $RESPONSE = response
191
- $VHOST = self
192
-
193
- @on_request.each { |x| x.call(request, self, client) }
194
-
195
- unless @cancelled
196
- match = nil
197
- if @resources && Waitress::DirHandler.resources_handler.respond?(request, self)
198
- match = Waitress::DirHandler.resources_handler
199
- end
200
-
201
- self.each do |handler|
202
- match = handler if handler.respond?(request, self) && (match.nil? || handler.priority > match.priority)
203
- end
204
-
205
- if match.nil?
206
- Waitress::Chef.error 404, request, response, client, self
207
- else
208
- match.serve! request, response, client, self
209
- end
210
- end
211
-
212
- @after_request.each { |x| x.call(request, response, self, client) }
213
- response.serve(client) unless (response.done? || client.closed?)
214
- end
215
-
216
- end
217
- end
1
+ module Waitress
2
+ # The VHost class is responsible for the actions of a Virtual Host, that is
3
+ # reacting to a certain subdomain and handling the requests that are sent to it.
4
+ # The requests are managed through the usage of +Waitress::Handler+ instances.
5
+ class Vhost < Array
6
+
7
+ attr_accessor :priority
8
+ attr_accessor :domain
9
+ attr_accessor :load_path
10
+
11
+ attr_accessor :combos
12
+ attr_accessor :libraries
13
+
14
+ # Create a new Virtual Host to manage traffic on a Subdomain (Host header)
15
+ # Params:
16
+ # +pattern+:: The regex pattern used to match this VHost to subdomain(s)
17
+ # +priority+:: The priority of the VHost. If multiple VHosts match the subdomain,
18
+ # the VHost with the highest priority will be chosen. Default: 50
19
+ def initialize pattern, priority=50
20
+ @domain = pattern
21
+ @priority = priority
22
+ @load_path = []
23
+ @libdir = "~/.waitress/www/libs"
24
+ @liburi = "libraries"
25
+
26
+ @libraries = {}
27
+ @combos = {}
28
+
29
+ @on_request = []
30
+ @after_request = []
31
+
32
+ enable_waitress_resources
33
+ end
34
+
35
+ # Register a listener that will be triggered once a request has been received
36
+ # by this VHost, but before it has been passed to a listener or served. Use this
37
+ # to modify a request before it is handled.
38
+ # The Block should take arguments:
39
+ # +request+:: The +Waitress::Request+ object
40
+ # +vhost+:: The VirtualHost instance
41
+ # +client+:: The Client Socket object
42
+ def on_request &block
43
+ @on_request << block
44
+ end
45
+
46
+ # Register a listener that will be triggered once a request has been received
47
+ # by this VHost, after it has been handled, but before it is served.
48
+ # The Block should take arguments:
49
+ # +request+:: The +Waitress::Request+ object
50
+ # +response+:: The +Waitress::Response+ object
51
+ # +vhost+:: The VirtualHost instance
52
+ # +client+:: The Client Socket object
53
+ def after_request &block
54
+ @after_request << block
55
+ end
56
+
57
+ # Call this to disable the Waitress Handler (Waitress' default CSS, JS, 404 and Index)
58
+ def disable_waitress_resources
59
+ @resources = false
60
+ end
61
+
62
+ # Call this to enable the Waitress Handler (Waitress' default CSS, JS, 404 and Index)
63
+ def enable_waitress_resources
64
+ @resources = true
65
+ end
66
+
67
+ # Returns true if the VHost has the Waitress Handler enabled (Waitress' default CSS, JS, 404 and Index)
68
+ def resources?
69
+ @resources
70
+ end
71
+
72
+ # Change the default 404 page for the VHost. This should be an absolute file path to your 404 page
73
+ # file that you wish to use
74
+ def set_404 link
75
+ @page_404 = link
76
+ end
77
+
78
+ # Get the absolute file path for the 404 page to use for this VHost. May be nil.
79
+ def get_404
80
+ @page_404
81
+ end
82
+
83
+ # Add a Document Root for this VHost. This document root will contain all of your
84
+ # public files that can be served by the vhost.
85
+ # Params:
86
+ # +dir+:: The directory for the Document Root
87
+ # +priority+:: The priority for the directory. If multiple Handlers respond to the target
88
+ # URI, the one with the highest priority will be chosen. Default: 50
89
+ def root dir, priority=50
90
+ self << Waitress::DirHandler.new(File.expand_path(dir), priority)
91
+ end
92
+
93
+ # Internal
94
+ def set_configure conf
95
+ @configuration = conf
96
+ end
97
+
98
+ # Set the directory in which Libraries are contained. Libraries are specially handled by
99
+ # waitress to be loaded into .wrb files and handlers. Default: "libs/"
100
+ # This file will contain your CSS, JS and any other libraries.
101
+ def libdir name
102
+ @libdir = File.expand_path(name)
103
+ end
104
+
105
+ # Change the uri that Libraries should be accessed from. Libraries present in the "libs/"
106
+ # directory are served from this URI. This URI is relative to the base "/" uri for the VirtualHost,
107
+ # for example, a LibUri of "libraries/" (the default) will be accessed by "your.site/libraries/lib_name"
108
+ def liburi name=nil
109
+ @liburi = name unless name.nil?
110
+ @liburi
111
+ end
112
+
113
+ # Bind a library to a name. By default, when libraries are found in the css/ and js/ folders of your
114
+ # lib directory, they are loaded under the lib name of "filename.type", with type being .css or .js.
115
+ # By binding a library, you can give this a different name based on the file found by regular expression,
116
+ # for example, binding /jquery/ to "jquery" will match any filenames containing 'jquery', meaning the full
117
+ # name of 'jquery-ver.sion' is matched, and can be accessed simply by "jquery"
118
+ # Params:
119
+ # +pattern+:: The regular expression to check files against. This will match the first file it finds with
120
+ # the expression to the library.
121
+ # +type+:: The type of file. This should be a symbol of either :js or :css, or any other supported lib types
122
+ # +name+:: The new name to reference this library by
123
+ # +options+:: Any extra options to use when loading the library (to be used in the future)
124
+ def bind_lib pattern, type, name, *options
125
+ lib = { :pattern => pattern, :bindtype => type, :options => options}
126
+ @libraries[name.to_sym] = lib
127
+ end
128
+
129
+ # Define a combination of libraries. Calling this method will bind all the libaries listed under one common
130
+ # name that can be loaded into .wrb files and handlers using combo(). This is used to load a collection of
131
+ # libraries simply and easily without repeating lib() methods.
132
+ # Params:
133
+ # +name+:: The desired name of the combo
134
+ # +targets+:: A list of all the libraries to bind to this combo
135
+ def combo name, *targets
136
+ @combos[name.to_sym] = targets
137
+ targets
138
+ end
139
+
140
+ # Internal
141
+ def parse_libraries
142
+ self << Waitress::LibraryHandler.new(@libraries, @libdir, @liburi, self)
143
+ end
144
+
145
+ # Internal (called on Server Start)
146
+ def on_server_start srv
147
+ parse_libraries
148
+ end
149
+
150
+ # Used to define the load path for the VHost. The Load Path defines what files can be
151
+ # included from outside of the public web directory, such as database backend or
152
+ # authentication. These files are not available to the public, but can be included by
153
+ # the .wrb files.
154
+ # Params:
155
+ # +dir+: The directory to use for the loadpath. If a string is provided, it is added,
156
+ # however, if an array is provided, it will override with the array.
157
+ def includes dir
158
+ if dir.is_a? String
159
+ load_path << File.expand_path(dir)
160
+ elsif dir.is_a? Array
161
+ load_path = dir.map { |x| File.expand_path(x) }
162
+ end
163
+ end
164
+
165
+ # Cancel the current request (don't serve the response)
166
+ def cancel_request
167
+ @cancelled = true
168
+ end
169
+
170
+ # Define a rewrite rule. A rewrite rule is used to rewrite a URL's path
171
+ # before it is handled. Keep in mind that this does not function for a query string,
172
+ # which should instead be handled with the on_request event.
173
+ # Params;
174
+ # +pattern+:: The pattern to match the URL against
175
+ # +newpath+:: The new path to replace the matched pattern with. This can include
176
+ # capture groups through the use of \\1 (where 1 is the capture group number)
177
+ def rewrite pattern, newpath
178
+ on_request do |request, vhost|
179
+ request.path = request.path.gsub(pattern, newpath)
180
+ end
181
+ end
182
+
183
+ # Internal (matches requests)
184
+ def handle_request request, client
185
+ @cancelled = false
186
+
187
+ response = Waitress::Response.new
188
+
189
+ $REQUEST = request
190
+ $RESPONSE = response
191
+ $VHOST = self
192
+
193
+ @on_request.each { |x| x.call(request, self, client) }
194
+
195
+ unless @cancelled
196
+ match = nil
197
+ if @resources && Waitress::DirHandler.resources_handler.respond?(request, self)
198
+ match = Waitress::DirHandler.resources_handler
199
+ end
200
+
201
+ self.each do |handler|
202
+ match = handler if handler.respond?(request, self) && (match.nil? || handler.priority > match.priority)
203
+ end
204
+
205
+ if match.nil?
206
+ Waitress::Chef.error 404, request, response, client, self
207
+ else
208
+ match.serve! request, response, client, self
209
+ end
210
+ end
211
+
212
+ @after_request.each { |x| x.call(request, response, self, client) }
213
+ response.serve(client) unless (response.done? || client.closed?)
214
+ end
215
+
216
+ end
217
+ end
data/lib/waitress.rb CHANGED
@@ -1,98 +1,98 @@
1
- require 'waitress/version'
2
- require 'waitress/util'
3
- require 'waitress/kernel'
4
- require 'waitress/configure'
5
- require 'waitress/parse/query'
6
-
7
- require 'waitress/server'
8
- require 'waitress/request'
9
- require 'waitress/response'
10
-
11
- require 'waitress/vhost'
12
- require 'waitress/handlers/handler'
13
- require 'waitress/handlers/dirhandler'
14
- require 'waitress/handlers/handler404'
15
- require 'waitress/handlers/libhandler'
16
- require 'waitress/chef'
17
-
18
- require 'waitress_http11'
19
-
20
- require 'go'
21
- require 'configfile'
22
- require 'fileutils'
23
-
24
- # The Base module for the Waitress Web Server, containing all the required
25
- # classes and utilities created by Waitress
26
- module Waitress
27
-
28
- # Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
29
- # for a set of Servers
30
- # Params:
31
- # +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
32
- # +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
33
- def self.serve! filesystem=false, rootdir=:default
34
- waitress = Waitress.new
35
- waitress.serve! filesystem, rootdir
36
- end
37
-
38
- # Create a configuration for a single Waitress Server instance. This should be called
39
- # from the config.rb file and nowhere else.
40
- # Params:
41
- # +args+:: The arguments to configure with. This should be a variable amount of arguments
42
- # representing what ports to run the server on. If no args are provided, port 80 will
43
- # be used as a default
44
- # +block+:: The block to call once the configuration has been created. Setup should be
45
- # done in here
46
- def self.configure! *args, &block
47
- Waitress::Configure.configure! *args, &block
48
- end
49
-
50
- # Create a new Launch Instance, used to serve a simple Waitress Server from either the
51
- # filesystem, or embedded.
52
- def self.new *args
53
- Waitress::Launcher.new *args
54
- end
55
-
56
- class Launcher
57
-
58
- # Create a new launcher. This is responsible for creating Waitress server instances
59
- # from either the Filesystem, or being embedded in an application
60
- def initialize waitress_root="~/.waitress"
61
- @waitress_root = File.expand_path waitress_root
62
- end
63
-
64
- # Serve a Waitress server from either the Filesystem or embedded in an application
65
- def serve! filesystem=false, rootdir=:default
66
- if filesystem
67
- serve_filesystem rootdir
68
- else
69
- serve
70
- end
71
- end
72
-
73
- :private
74
- def config
75
- ConfigFile.new File.join(@waitress_root, "config.yml"),
76
- {"server_root" => File.join(@waitress_root, "www")}, :yaml
77
- end
78
-
79
- def serve_filesystem rootdir
80
- if rootdir == :default
81
- FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
82
- cfg = config
83
- cfg.load
84
- @root = File.expand_path cfg["server_root"]
85
- else
86
- @root = rootdir
87
- end
88
- # s = serve
89
- # Waitress::Configure.new s, @root
90
- # s
91
- Waitress::Configure.new @root
92
- end
93
-
94
- def serve
95
- Waitress::HttpServer.new
96
- end
97
- end
98
- end
1
+ require 'waitress/version'
2
+ require 'waitress/util'
3
+ require 'waitress/kernel'
4
+ require 'waitress/configure'
5
+ require 'waitress/parse/query'
6
+
7
+ require 'waitress/server'
8
+ require 'waitress/request'
9
+ require 'waitress/response'
10
+
11
+ require 'waitress/vhost'
12
+ require 'waitress/handlers/handler'
13
+ require 'waitress/handlers/dirhandler'
14
+ require 'waitress/handlers/handler404'
15
+ require 'waitress/handlers/libhandler'
16
+ require 'waitress/chef'
17
+
18
+ require 'waitress_http11'
19
+
20
+ require 'go'
21
+ require 'configfile'
22
+ require 'fileutils'
23
+
24
+ # The Base module for the Waitress Web Server, containing all the required
25
+ # classes and utilities created by Waitress
26
+ module Waitress
27
+
28
+ # Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
29
+ # for a set of Servers
30
+ # Params:
31
+ # +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
32
+ # +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
33
+ def self.serve! filesystem=false, rootdir=:default
34
+ waitress = Waitress.new
35
+ waitress.serve! filesystem, rootdir
36
+ end
37
+
38
+ # Create a configuration for a single Waitress Server instance. This should be called
39
+ # from the config.rb file and nowhere else.
40
+ # Params:
41
+ # +args+:: The arguments to configure with. This should be a variable amount of arguments
42
+ # representing what ports to run the server on. If no args are provided, port 80 will
43
+ # be used as a default
44
+ # +block+:: The block to call once the configuration has been created. Setup should be
45
+ # done in here
46
+ def self.configure! *args, &block
47
+ Waitress::Configure.configure! *args, &block
48
+ end
49
+
50
+ # Create a new Launch Instance, used to serve a simple Waitress Server from either the
51
+ # filesystem, or embedded.
52
+ def self.new *args
53
+ Waitress::Launcher.new *args
54
+ end
55
+
56
+ class Launcher
57
+
58
+ # Create a new launcher. This is responsible for creating Waitress server instances
59
+ # from either the Filesystem, or being embedded in an application
60
+ def initialize waitress_root="~/.waitress"
61
+ @waitress_root = File.expand_path waitress_root
62
+ end
63
+
64
+ # Serve a Waitress server from either the Filesystem or embedded in an application
65
+ def serve! filesystem=false, rootdir=:default
66
+ if filesystem
67
+ serve_filesystem rootdir
68
+ else
69
+ serve
70
+ end
71
+ end
72
+
73
+ :private
74
+ def config
75
+ ConfigFile.new File.join(@waitress_root, "config.yml"),
76
+ {"server_root" => File.join(@waitress_root, "www")}, :yaml
77
+ end
78
+
79
+ def serve_filesystem rootdir
80
+ if rootdir == :default
81
+ FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
82
+ cfg = config
83
+ cfg.load
84
+ @root = File.expand_path cfg["server_root"]
85
+ else
86
+ @root = rootdir
87
+ end
88
+ # s = serve
89
+ # Waitress::Configure.new s, @root
90
+ # s
91
+ Waitress::Configure.new @root
92
+ end
93
+
94
+ def serve
95
+ Waitress::HttpServer.new
96
+ end
97
+ end
98
+ end
Binary file