waitress-core 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/Rakefile +13 -13
- data/bin/waitress +22 -22
- data/ext/Thanks.md +1 -1
- data/ext/waitress_http11/ext_help.h +15 -15
- data/ext/waitress_http11/extconf.rb +6 -6
- data/ext/waitress_http11/http11.c +532 -532
- data/ext/waitress_http11/http11_parser.c +1216 -1216
- data/ext/waitress_http11/http11_parser.h +49 -49
- data/ext/waitress_http11/http11_parser.java.rl +171 -171
- data/ext/waitress_http11/http11_parser.rl +165 -165
- data/ext/waitress_http11/http11_parser_common.rl +55 -55
- data/ext/waitress_http11/http11_wrb_parser.h +91 -91
- data/lib/waitress/chef.rb +113 -113
- data/lib/waitress/configure.rb +121 -121
- data/lib/waitress/evalbind.rb +9 -9
- data/lib/waitress/handlers/dirhandler.rb +39 -39
- data/lib/waitress/handlers/handler.rb +57 -57
- data/lib/waitress/handlers/handler404.rb +25 -25
- data/lib/waitress/handlers/libhandler.rb +58 -58
- data/lib/waitress/kernel.rb +182 -182
- data/lib/waitress/parse/query.rb +60 -60
- data/lib/waitress/request.rb +45 -45
- data/lib/waitress/resources/default_config.rb +52 -52
- data/lib/waitress/resources/http/404.html +18 -18
- data/lib/waitress/resources/http/css/hack.css +37 -37
- data/lib/waitress/resources/http/css/waitress.css +57 -57
- data/lib/waitress/resources/http/fonts/svg/latin/hack-bold-latin-webfont.svg +240 -240
- data/lib/waitress/resources/http/fonts/svg/latin/hack-bolditalic-latin-webfont.svg +240 -240
- data/lib/waitress/resources/http/fonts/svg/latin/hack-italic-latin-webfont.svg +240 -240
- data/lib/waitress/resources/http/fonts/svg/latin/hack-regular-latin-webfont.svg +240 -240
- data/lib/waitress/resources/http/index.html +15 -15
- data/lib/waitress/response.rb +105 -105
- data/lib/waitress/server.rb +161 -158
- data/lib/waitress/util.rb +707 -707
- data/lib/waitress/version.rb +3 -3
- data/lib/waitress/vhost.rb +217 -217
- data/lib/waitress.rb +106 -106
- data/lib/waitress_http11.so +0 -0
- data/waitress-core.gemspec +29 -29
- metadata +3 -3
- data/lib/waitress_http11.bundle +0 -0
data/lib/waitress/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Waitress
|
2
|
-
VERSION = "0.2.
|
3
|
-
end
|
1
|
+
module Waitress
|
2
|
+
VERSION = "0.2.2"
|
3
|
+
end
|
data/lib/waitress/vhost.rb
CHANGED
@@ -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,106 +1,106 @@
|
|
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
|
-
require 'waitress/evalbind'
|
18
|
-
|
19
|
-
require 'waitress_http11'
|
20
|
-
|
21
|
-
require 'go'
|
22
|
-
require 'configfile'
|
23
|
-
require 'fileutils'
|
24
|
-
|
25
|
-
# The Base module for the Waitress Web Server, containing all the required
|
26
|
-
# classes and utilities created by Waitress
|
27
|
-
module Waitress
|
28
|
-
|
29
|
-
SERVERS = []
|
30
|
-
|
31
|
-
at_exit do
|
32
|
-
SERVERS.each { |x| x.killall }
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
|
36
|
-
# Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
|
37
|
-
# for a set of Servers
|
38
|
-
# Params:
|
39
|
-
# +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
|
40
|
-
# +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
|
41
|
-
def self.serve! filesystem=false, rootdir=:default
|
42
|
-
waitress = Waitress.new
|
43
|
-
waitress.serve! filesystem, rootdir
|
44
|
-
end
|
45
|
-
|
46
|
-
# Create a configuration for a single Waitress Server instance. This should be called
|
47
|
-
# from the config.rb file and nowhere else.
|
48
|
-
# Params:
|
49
|
-
# +args+:: The arguments to configure with. This should be a variable amount of arguments
|
50
|
-
# representing what ports to run the server on. If no args are provided, port 80 will
|
51
|
-
# be used as a default
|
52
|
-
# +block+:: The block to call once the configuration has been created. Setup should be
|
53
|
-
# done in here
|
54
|
-
def self.configure! *args, &block
|
55
|
-
Waitress::Configure.configure! *args, &block
|
56
|
-
end
|
57
|
-
|
58
|
-
# Create a new Launch Instance, used to serve a simple Waitress Server from either the
|
59
|
-
# filesystem, or embedded.
|
60
|
-
def self.new *args
|
61
|
-
Waitress::Launcher.new *args
|
62
|
-
end
|
63
|
-
|
64
|
-
class Launcher
|
65
|
-
|
66
|
-
# Create a new launcher. This is responsible for creating Waitress server instances
|
67
|
-
# from either the Filesystem, or being embedded in an application
|
68
|
-
def initialize waitress_root="~/.waitress"
|
69
|
-
@waitress_root = File.expand_path waitress_root
|
70
|
-
end
|
71
|
-
|
72
|
-
# Serve a Waitress server from either the Filesystem or embedded in an application
|
73
|
-
def serve! filesystem=false, rootdir=:default
|
74
|
-
if filesystem
|
75
|
-
serve_filesystem rootdir
|
76
|
-
else
|
77
|
-
serve
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
:private
|
82
|
-
def config
|
83
|
-
ConfigFile.new File.join(@waitress_root, "config.yml"),
|
84
|
-
{"server_root" => File.join(@waitress_root, "www")}, :yaml
|
85
|
-
end
|
86
|
-
|
87
|
-
def serve_filesystem rootdir
|
88
|
-
if rootdir == :default
|
89
|
-
FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
|
90
|
-
cfg = config
|
91
|
-
cfg.load
|
92
|
-
@root = File.expand_path cfg["server_root"]
|
93
|
-
else
|
94
|
-
@root = rootdir
|
95
|
-
end
|
96
|
-
# s = serve
|
97
|
-
# Waitress::Configure.new s, @root
|
98
|
-
# s
|
99
|
-
Waitress::Configure.new @root
|
100
|
-
end
|
101
|
-
|
102
|
-
def serve
|
103
|
-
Waitress::HttpServer.new
|
104
|
-
end
|
105
|
-
end
|
106
|
-
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
|
+
require 'waitress/evalbind'
|
18
|
+
|
19
|
+
require 'waitress_http11'
|
20
|
+
|
21
|
+
require 'go'
|
22
|
+
require 'configfile'
|
23
|
+
require 'fileutils'
|
24
|
+
|
25
|
+
# The Base module for the Waitress Web Server, containing all the required
|
26
|
+
# classes and utilities created by Waitress
|
27
|
+
module Waitress
|
28
|
+
|
29
|
+
SERVERS = []
|
30
|
+
|
31
|
+
at_exit do
|
32
|
+
SERVERS.each { |x| x.killall }
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
|
37
|
+
# for a set of Servers
|
38
|
+
# Params:
|
39
|
+
# +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
|
40
|
+
# +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
|
41
|
+
def self.serve! filesystem=false, rootdir=:default
|
42
|
+
waitress = Waitress.new
|
43
|
+
waitress.serve! filesystem, rootdir
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a configuration for a single Waitress Server instance. This should be called
|
47
|
+
# from the config.rb file and nowhere else.
|
48
|
+
# Params:
|
49
|
+
# +args+:: The arguments to configure with. This should be a variable amount of arguments
|
50
|
+
# representing what ports to run the server on. If no args are provided, port 80 will
|
51
|
+
# be used as a default
|
52
|
+
# +block+:: The block to call once the configuration has been created. Setup should be
|
53
|
+
# done in here
|
54
|
+
def self.configure! *args, &block
|
55
|
+
Waitress::Configure.configure! *args, &block
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create a new Launch Instance, used to serve a simple Waitress Server from either the
|
59
|
+
# filesystem, or embedded.
|
60
|
+
def self.new *args
|
61
|
+
Waitress::Launcher.new *args
|
62
|
+
end
|
63
|
+
|
64
|
+
class Launcher
|
65
|
+
|
66
|
+
# Create a new launcher. This is responsible for creating Waitress server instances
|
67
|
+
# from either the Filesystem, or being embedded in an application
|
68
|
+
def initialize waitress_root="~/.waitress"
|
69
|
+
@waitress_root = File.expand_path waitress_root
|
70
|
+
end
|
71
|
+
|
72
|
+
# Serve a Waitress server from either the Filesystem or embedded in an application
|
73
|
+
def serve! filesystem=false, rootdir=:default
|
74
|
+
if filesystem
|
75
|
+
serve_filesystem rootdir
|
76
|
+
else
|
77
|
+
serve
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
:private
|
82
|
+
def config
|
83
|
+
ConfigFile.new File.join(@waitress_root, "config.yml"),
|
84
|
+
{"server_root" => File.join(@waitress_root, "www")}, :yaml
|
85
|
+
end
|
86
|
+
|
87
|
+
def serve_filesystem rootdir
|
88
|
+
if rootdir == :default
|
89
|
+
FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
|
90
|
+
cfg = config
|
91
|
+
cfg.load
|
92
|
+
@root = File.expand_path cfg["server_root"]
|
93
|
+
else
|
94
|
+
@root = rootdir
|
95
|
+
end
|
96
|
+
# s = serve
|
97
|
+
# Waitress::Configure.new s, @root
|
98
|
+
# s
|
99
|
+
Waitress::Configure.new @root
|
100
|
+
end
|
101
|
+
|
102
|
+
def serve
|
103
|
+
Waitress::HttpServer.new
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
Binary file
|