waitress-core 0.2.4 → 0.3.0
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 +17 -17
- 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.rb +100 -99
- data/lib/waitress/chef.rb +113 -113
- data/lib/waitress/configure.rb +127 -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 +135 -58
- data/lib/waitress/kernel.rb +189 -189
- 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/default_less.yml +7 -0
- 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/eot/latin/hack-bold-latin-webfont.eot +0 -0
- data/lib/waitress/resources/http/fonts/eot/latin/hack-bolditalic-latin-webfont.eot +0 -0
- data/lib/waitress/resources/http/fonts/eot/latin/hack-italic-latin-webfont.eot +0 -0
- data/lib/waitress/resources/http/fonts/eot/latin/hack-regular-latin-webfont.eot +0 -0
- 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/fonts/web-ttf/latin/hack-bold-latin-webfont.ttf +0 -0
- data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bolditalic-latin-webfont.ttf +0 -0
- data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-italic-latin-webfont.ttf +0 -0
- data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-regular-latin-webfont.ttf +0 -0
- data/lib/waitress/resources/http/fonts/woff/latin/hack-bold-latin-webfont.woff +0 -0
- data/lib/waitress/resources/http/fonts/woff/latin/hack-bolditalic-latin-webfont.woff +0 -0
- data/lib/waitress/resources/http/fonts/woff/latin/hack-italic-latin-webfont.woff +0 -0
- data/lib/waitress/resources/http/fonts/woff/latin/hack-regular-latin-webfont.woff +0 -0
- data/lib/waitress/resources/http/fonts/woff2/latin/hack-bold-latin-webfont.woff2 +0 -0
- data/lib/waitress/resources/http/fonts/woff2/latin/hack-bolditalic-latin-webfont.woff2 +0 -0
- data/lib/waitress/resources/http/fonts/woff2/latin/hack-italic-latin-webfont.woff2 +0 -0
- data/lib/waitress/resources/http/fonts/woff2/latin/hack-regular-latin-webfont.woff2 +0 -0
- data/lib/waitress/resources/http/img/404.png +0 -0
- data/lib/waitress/resources/http/index.html +15 -15
- data/lib/waitress/response.rb +105 -105
- data/lib/waitress/server.rb +160 -160
- data/lib/waitress/util/less_watcher.rb +56 -0
- data/lib/waitress/{util.rb → util/util.rb} +707 -707
- data/lib/waitress/version.rb +3 -3
- data/lib/waitress/vhost.rb +229 -227
- data/lib/waitress_http11.so +0 -0
- data/waitress-core.gemspec +32 -29
- metadata +48 -4
- data/lib/waitress_http11.bundle +0 -0
@@ -1,55 +1,55 @@
|
|
1
|
-
%%{
|
2
|
-
|
3
|
-
machine http_parser_common;
|
4
|
-
|
5
|
-
#### HTTP PROTOCOL GRAMMAR
|
6
|
-
# line endings
|
7
|
-
CRLF = "\r\n";
|
8
|
-
|
9
|
-
# character types
|
10
|
-
CTL = (cntrl | 127);
|
11
|
-
safe = ("$" | "-" | "_" | ".");
|
12
|
-
extra = ("!" | "*" | "'" | "(" | ")" | ",");
|
13
|
-
reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
|
14
|
-
sorta_safe = ("\"" | "<" | ">");
|
15
|
-
unsafe = (CTL | " " | "#" | "%" | sorta_safe);
|
16
|
-
national = any -- (alpha | digit | reserved | extra | safe | unsafe);
|
17
|
-
unreserved = (alpha | digit | safe | extra | national);
|
18
|
-
escape = ("%" xdigit xdigit);
|
19
|
-
uchar = (unreserved | escape | sorta_safe);
|
20
|
-
pchar = (uchar | ":" | "@" | "&" | "=" | "+");
|
21
|
-
tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
|
22
|
-
|
23
|
-
# elements
|
24
|
-
token = (ascii -- (CTL | tspecials));
|
25
|
-
|
26
|
-
# URI schemes and absolute paths
|
27
|
-
scheme = ( alpha | digit | "+" | "-" | "." )* ;
|
28
|
-
absolute_uri = (scheme ":" (uchar | reserved )*);
|
29
|
-
|
30
|
-
path = ( pchar+ ( "/" pchar* )* ) ;
|
31
|
-
query = ( uchar | reserved )* %query_string ;
|
32
|
-
param = ( pchar | "/" )* ;
|
33
|
-
params = ( param ( ";" param )* ) ;
|
34
|
-
rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
|
35
|
-
absolute_path = ( "/"+ rel_path );
|
36
|
-
|
37
|
-
Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
|
38
|
-
Fragment = ( uchar | reserved )* >mark %fragment;
|
39
|
-
Method = ( upper | digit | safe ){1,20} >mark %request_method;
|
40
|
-
|
41
|
-
http_number = ( digit+ "." digit+ ) ;
|
42
|
-
HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ;
|
43
|
-
Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
|
44
|
-
|
45
|
-
field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field;
|
46
|
-
|
47
|
-
field_value = any* >start_value %write_value;
|
48
|
-
|
49
|
-
message_header = field_name ":" " "* field_value :> CRLF;
|
50
|
-
|
51
|
-
Request = Request_Line ( message_header )* ( CRLF @done );
|
52
|
-
|
53
|
-
main := Request;
|
54
|
-
|
55
|
-
}%%
|
1
|
+
%%{
|
2
|
+
|
3
|
+
machine http_parser_common;
|
4
|
+
|
5
|
+
#### HTTP PROTOCOL GRAMMAR
|
6
|
+
# line endings
|
7
|
+
CRLF = "\r\n";
|
8
|
+
|
9
|
+
# character types
|
10
|
+
CTL = (cntrl | 127);
|
11
|
+
safe = ("$" | "-" | "_" | ".");
|
12
|
+
extra = ("!" | "*" | "'" | "(" | ")" | ",");
|
13
|
+
reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
|
14
|
+
sorta_safe = ("\"" | "<" | ">");
|
15
|
+
unsafe = (CTL | " " | "#" | "%" | sorta_safe);
|
16
|
+
national = any -- (alpha | digit | reserved | extra | safe | unsafe);
|
17
|
+
unreserved = (alpha | digit | safe | extra | national);
|
18
|
+
escape = ("%" xdigit xdigit);
|
19
|
+
uchar = (unreserved | escape | sorta_safe);
|
20
|
+
pchar = (uchar | ":" | "@" | "&" | "=" | "+");
|
21
|
+
tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
|
22
|
+
|
23
|
+
# elements
|
24
|
+
token = (ascii -- (CTL | tspecials));
|
25
|
+
|
26
|
+
# URI schemes and absolute paths
|
27
|
+
scheme = ( alpha | digit | "+" | "-" | "." )* ;
|
28
|
+
absolute_uri = (scheme ":" (uchar | reserved )*);
|
29
|
+
|
30
|
+
path = ( pchar+ ( "/" pchar* )* ) ;
|
31
|
+
query = ( uchar | reserved )* %query_string ;
|
32
|
+
param = ( pchar | "/" )* ;
|
33
|
+
params = ( param ( ";" param )* ) ;
|
34
|
+
rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
|
35
|
+
absolute_path = ( "/"+ rel_path );
|
36
|
+
|
37
|
+
Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
|
38
|
+
Fragment = ( uchar | reserved )* >mark %fragment;
|
39
|
+
Method = ( upper | digit | safe ){1,20} >mark %request_method;
|
40
|
+
|
41
|
+
http_number = ( digit+ "." digit+ ) ;
|
42
|
+
HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ;
|
43
|
+
Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
|
44
|
+
|
45
|
+
field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field;
|
46
|
+
|
47
|
+
field_value = any* >start_value %write_value;
|
48
|
+
|
49
|
+
message_header = field_name ":" " "* field_value :> CRLF;
|
50
|
+
|
51
|
+
Request = Request_Line ( message_header )* ( CRLF @done );
|
52
|
+
|
53
|
+
main := Request;
|
54
|
+
|
55
|
+
}%%
|
@@ -1,91 +1,91 @@
|
|
1
|
-
#ifndef RSTRING_PTR
|
2
|
-
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
3
|
-
#endif
|
4
|
-
#ifndef RSTRING_LEN
|
5
|
-
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
6
|
-
#endif
|
7
|
-
|
8
|
-
char *substr(const char *buff, int start, int len) {
|
9
|
-
char subbuff[len + 1];
|
10
|
-
memcpy(subbuff, &buff[start], len);
|
11
|
-
subbuff[len] = '\0';
|
12
|
-
return strdup(subbuff);
|
13
|
-
}
|
14
|
-
|
15
|
-
int mat(char *str1, char *str2) {
|
16
|
-
return strcmp(str1, str2) == 0;
|
17
|
-
}
|
18
|
-
|
19
|
-
VALUE WRB_Parse(VALUE self, VALUE string, VALUE buffer) {
|
20
|
-
char *sptr = RSTRING_PTR(string);
|
21
|
-
long slen = RSTRING_LEN(string);
|
22
|
-
|
23
|
-
char *tar = "<?ruby";
|
24
|
-
char tarlen = 6;
|
25
|
-
char *end = "?>";
|
26
|
-
char endlen = 2;
|
27
|
-
|
28
|
-
int i = 0;
|
29
|
-
char pc = NULL;
|
30
|
-
int line_cur = 1;
|
31
|
-
int line = 1;
|
32
|
-
|
33
|
-
while (i < slen) {
|
34
|
-
char c = sptr[i];
|
35
|
-
if (c == '\n') line_cur += 1;
|
36
|
-
|
37
|
-
int open_e = i + tarlen;
|
38
|
-
char *open_s = substr(sptr, i, tarlen);
|
39
|
-
|
40
|
-
if (mat(open_s, tar) && pc != '\\') {
|
41
|
-
line = line_cur;
|
42
|
-
int j = open_e;
|
43
|
-
int search = 1;
|
44
|
-
int q1 = 0; int q2 = 0;
|
45
|
-
while (j < slen && search) {
|
46
|
-
char cc = sptr[j];
|
47
|
-
if (cc == '\n') line_cur += 1;
|
48
|
-
|
49
|
-
int close_e = j + endlen;
|
50
|
-
char *close_s = substr(sptr, j, endlen);
|
51
|
-
|
52
|
-
if (sptr[j-1] != '\\') {
|
53
|
-
if (cc == '\"') q1 = (q1 == 0 ? 1 : 0);
|
54
|
-
if (cc == '\'') q2 = (q2 == 0 ? 1 : 0);
|
55
|
-
if (mat(close_s, end) && !q1 && !q2) {
|
56
|
-
i = close_e - 1;
|
57
|
-
search = 0;
|
58
|
-
char *rb_ev = substr(sptr, open_e, j - open_e);
|
59
|
-
rb_yield_values(2, rb_str_new2(rb_ev), INT2NUM(line));
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
j+=1;
|
64
|
-
}
|
65
|
-
|
66
|
-
if (j == slen && search) {
|
67
|
-
char *rb_ev = substr(sptr, open_e, j);
|
68
|
-
i = slen;
|
69
|
-
rb_eval_string(rb_ev);
|
70
|
-
}
|
71
|
-
} else if (c == '\\') {
|
72
|
-
if (!mat(substr(sptr, i+1, tarlen), tar)) {
|
73
|
-
char strbuf[2] = "\0";
|
74
|
-
strbuf[0] = c;
|
75
|
-
rb_funcall(buffer, rb_intern("write"), 1, rb_str_new2(strbuf));
|
76
|
-
}
|
77
|
-
} else {
|
78
|
-
char strbuf[2] = "\0";
|
79
|
-
strbuf[0] = c;
|
80
|
-
rb_funcall(buffer, rb_intern("write"), 1, rb_str_new2(strbuf));
|
81
|
-
}
|
82
|
-
|
83
|
-
pc = c;
|
84
|
-
i += 1;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
void init_parse(VALUE rubyModule) {
|
89
|
-
VALUE cWaParse = rb_define_class_under(rubyModule, "WRBParser", rb_cObject);
|
90
|
-
rb_define_module_function(cWaParse, "parse!", WRB_Parse, 2);
|
91
|
-
}
|
1
|
+
#ifndef RSTRING_PTR
|
2
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
3
|
+
#endif
|
4
|
+
#ifndef RSTRING_LEN
|
5
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
6
|
+
#endif
|
7
|
+
|
8
|
+
char *substr(const char *buff, int start, int len) {
|
9
|
+
char subbuff[len + 1];
|
10
|
+
memcpy(subbuff, &buff[start], len);
|
11
|
+
subbuff[len] = '\0';
|
12
|
+
return strdup(subbuff);
|
13
|
+
}
|
14
|
+
|
15
|
+
int mat(char *str1, char *str2) {
|
16
|
+
return strcmp(str1, str2) == 0;
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE WRB_Parse(VALUE self, VALUE string, VALUE buffer) {
|
20
|
+
char *sptr = RSTRING_PTR(string);
|
21
|
+
long slen = RSTRING_LEN(string);
|
22
|
+
|
23
|
+
char *tar = "<?ruby";
|
24
|
+
char tarlen = 6;
|
25
|
+
char *end = "?>";
|
26
|
+
char endlen = 2;
|
27
|
+
|
28
|
+
int i = 0;
|
29
|
+
char pc = NULL;
|
30
|
+
int line_cur = 1;
|
31
|
+
int line = 1;
|
32
|
+
|
33
|
+
while (i < slen) {
|
34
|
+
char c = sptr[i];
|
35
|
+
if (c == '\n') line_cur += 1;
|
36
|
+
|
37
|
+
int open_e = i + tarlen;
|
38
|
+
char *open_s = substr(sptr, i, tarlen);
|
39
|
+
|
40
|
+
if (mat(open_s, tar) && pc != '\\') {
|
41
|
+
line = line_cur;
|
42
|
+
int j = open_e;
|
43
|
+
int search = 1;
|
44
|
+
int q1 = 0; int q2 = 0;
|
45
|
+
while (j < slen && search) {
|
46
|
+
char cc = sptr[j];
|
47
|
+
if (cc == '\n') line_cur += 1;
|
48
|
+
|
49
|
+
int close_e = j + endlen;
|
50
|
+
char *close_s = substr(sptr, j, endlen);
|
51
|
+
|
52
|
+
if (sptr[j-1] != '\\') {
|
53
|
+
if (cc == '\"') q1 = (q1 == 0 ? 1 : 0);
|
54
|
+
if (cc == '\'') q2 = (q2 == 0 ? 1 : 0);
|
55
|
+
if (mat(close_s, end) && !q1 && !q2) {
|
56
|
+
i = close_e - 1;
|
57
|
+
search = 0;
|
58
|
+
char *rb_ev = substr(sptr, open_e, j - open_e);
|
59
|
+
rb_yield_values(2, rb_str_new2(rb_ev), INT2NUM(line));
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
j+=1;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (j == slen && search) {
|
67
|
+
char *rb_ev = substr(sptr, open_e, j);
|
68
|
+
i = slen;
|
69
|
+
rb_eval_string(rb_ev);
|
70
|
+
}
|
71
|
+
} else if (c == '\\') {
|
72
|
+
if (!mat(substr(sptr, i+1, tarlen), tar)) {
|
73
|
+
char strbuf[2] = "\0";
|
74
|
+
strbuf[0] = c;
|
75
|
+
rb_funcall(buffer, rb_intern("write"), 1, rb_str_new2(strbuf));
|
76
|
+
}
|
77
|
+
} else {
|
78
|
+
char strbuf[2] = "\0";
|
79
|
+
strbuf[0] = c;
|
80
|
+
rb_funcall(buffer, rb_intern("write"), 1, rb_str_new2(strbuf));
|
81
|
+
}
|
82
|
+
|
83
|
+
pc = c;
|
84
|
+
i += 1;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
void init_parse(VALUE rubyModule) {
|
89
|
+
VALUE cWaParse = rb_define_class_under(rubyModule, "WRBParser", rb_cObject);
|
90
|
+
rb_define_module_function(cWaParse, "parse!", WRB_Parse, 2);
|
91
|
+
}
|
data/lib/waitress.rb
CHANGED
@@ -1,99 +1,100 @@
|
|
1
|
-
require 'waitress/version'
|
2
|
-
require 'waitress/util'
|
3
|
-
require 'waitress/
|
4
|
-
require 'waitress/
|
5
|
-
require 'waitress/
|
6
|
-
|
7
|
-
|
8
|
-
require 'waitress/
|
9
|
-
require 'waitress/
|
10
|
-
|
11
|
-
|
12
|
-
require 'waitress/
|
13
|
-
require 'waitress/handlers/
|
14
|
-
require 'waitress/handlers/
|
15
|
-
require 'waitress/handlers/
|
16
|
-
require 'waitress/
|
17
|
-
require 'waitress/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# +
|
34
|
-
|
35
|
-
|
36
|
-
waitress
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
cfg
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
# s
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
1
|
+
require 'waitress/version'
|
2
|
+
require 'waitress/util/util'
|
3
|
+
require 'waitress/util/less_watcher'
|
4
|
+
require 'waitress/kernel'
|
5
|
+
require 'waitress/configure'
|
6
|
+
require 'waitress/parse/query'
|
7
|
+
|
8
|
+
require 'waitress/server'
|
9
|
+
require 'waitress/request'
|
10
|
+
require 'waitress/response'
|
11
|
+
|
12
|
+
require 'waitress/vhost'
|
13
|
+
require 'waitress/handlers/handler'
|
14
|
+
require 'waitress/handlers/dirhandler'
|
15
|
+
require 'waitress/handlers/handler404'
|
16
|
+
require 'waitress/handlers/libhandler'
|
17
|
+
require 'waitress/chef'
|
18
|
+
require 'waitress/evalbind'
|
19
|
+
|
20
|
+
require 'waitress_http11'
|
21
|
+
|
22
|
+
require 'go'
|
23
|
+
require 'configfile'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
# The Base module for the Waitress Web Server, containing all the required
|
27
|
+
# classes and utilities created by Waitress
|
28
|
+
module Waitress
|
29
|
+
|
30
|
+
# Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
|
31
|
+
# for a set of Servers
|
32
|
+
# Params:
|
33
|
+
# +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
|
34
|
+
# +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
|
35
|
+
def self.serve! filesystem=false, rootdir=:default
|
36
|
+
waitress = Waitress.new
|
37
|
+
waitress.serve! filesystem, rootdir
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create a configuration for a single Waitress Server instance. This should be called
|
41
|
+
# from the config.rb file and nowhere else.
|
42
|
+
# Params:
|
43
|
+
# +args+:: The arguments to configure with. This should be a variable amount of arguments
|
44
|
+
# representing what ports to run the server on. If no args are provided, port 80 will
|
45
|
+
# be used as a default
|
46
|
+
# +block+:: The block to call once the configuration has been created. Setup should be
|
47
|
+
# done in here
|
48
|
+
def self.configure! *args, &block
|
49
|
+
Waitress::Configure.configure! *args, &block
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create a new Launch Instance, used to serve a simple Waitress Server from either the
|
53
|
+
# filesystem, or embedded.
|
54
|
+
def self.new *args
|
55
|
+
Waitress::Launcher.new *args
|
56
|
+
end
|
57
|
+
|
58
|
+
class Launcher
|
59
|
+
|
60
|
+
# Create a new launcher. This is responsible for creating Waitress server instances
|
61
|
+
# from either the Filesystem, or being embedded in an application
|
62
|
+
def initialize waitress_root="~/.waitress"
|
63
|
+
@waitress_root = File.expand_path waitress_root
|
64
|
+
end
|
65
|
+
|
66
|
+
# Serve a Waitress server from either the Filesystem or embedded in an application
|
67
|
+
def serve! filesystem=false, rootdir=:default
|
68
|
+
if filesystem
|
69
|
+
serve_filesystem rootdir
|
70
|
+
else
|
71
|
+
serve
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
:private
|
76
|
+
def config
|
77
|
+
ConfigFile.new File.join(@waitress_root, "config.yml"),
|
78
|
+
{"server_root" => File.join(@waitress_root, "www")}, :yaml
|
79
|
+
end
|
80
|
+
|
81
|
+
def serve_filesystem rootdir
|
82
|
+
if rootdir == :default
|
83
|
+
FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
|
84
|
+
cfg = config
|
85
|
+
cfg.load
|
86
|
+
@root = File.expand_path cfg["server_root"]
|
87
|
+
else
|
88
|
+
@root = rootdir
|
89
|
+
end
|
90
|
+
# s = serve
|
91
|
+
# Waitress::Configure.new s, @root
|
92
|
+
# s
|
93
|
+
Waitress::Configure.new @root
|
94
|
+
end
|
95
|
+
|
96
|
+
def serve
|
97
|
+
Waitress::HttpServer.new
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|