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.
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
@@ -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/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
- # Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
30
- # for a set of Servers
31
- # Params:
32
- # +filesystem+:: True if waitress should be loaded from the Filesystem. Default: false
33
- # +rootdir+:: The root directory to load waitress from, defaults to ~/.waitress
34
- def self.serve! filesystem=false, rootdir=:default
35
- waitress = Waitress.new
36
- waitress.serve! filesystem, rootdir
37
- end
38
-
39
- # Create a configuration for a single Waitress Server instance. This should be called
40
- # from the config.rb file and nowhere else.
41
- # Params:
42
- # +args+:: The arguments to configure with. This should be a variable amount of arguments
43
- # representing what ports to run the server on. If no args are provided, port 80 will
44
- # be used as a default
45
- # +block+:: The block to call once the configuration has been created. Setup should be
46
- # done in here
47
- def self.configure! *args, &block
48
- Waitress::Configure.configure! *args, &block
49
- end
50
-
51
- # Create a new Launch Instance, used to serve a simple Waitress Server from either the
52
- # filesystem, or embedded.
53
- def self.new *args
54
- Waitress::Launcher.new *args
55
- end
56
-
57
- class Launcher
58
-
59
- # Create a new launcher. This is responsible for creating Waitress server instances
60
- # from either the Filesystem, or being embedded in an application
61
- def initialize waitress_root="~/.waitress"
62
- @waitress_root = File.expand_path waitress_root
63
- end
64
-
65
- # Serve a Waitress server from either the Filesystem or embedded in an application
66
- def serve! filesystem=false, rootdir=:default
67
- if filesystem
68
- serve_filesystem rootdir
69
- else
70
- serve
71
- end
72
- end
73
-
74
- :private
75
- def config
76
- ConfigFile.new File.join(@waitress_root, "config.yml"),
77
- {"server_root" => File.join(@waitress_root, "www")}, :yaml
78
- end
79
-
80
- def serve_filesystem rootdir
81
- if rootdir == :default
82
- FileUtils.mkdir_p @waitress_root unless File.exist? @waitress_root
83
- cfg = config
84
- cfg.load
85
- @root = File.expand_path cfg["server_root"]
86
- else
87
- @root = rootdir
88
- end
89
- # s = serve
90
- # Waitress::Configure.new s, @root
91
- # s
92
- Waitress::Configure.new @root
93
- end
94
-
95
- def serve
96
- Waitress::HttpServer.new
97
- end
98
- end
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