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,189 +1,189 @@
1
- # The Kernel Module provides global methods that will provide the 'builtins' for .wrb files
2
- # and handlers. This is used to prevent verbose access of a namespace like Waitress::Global,
3
- # and instead provide them here. Because requests are handled in new Processes, these values
4
- # will change in each request and will not interfere.
5
- module ::Kernel
6
-
7
- # The +Waitress::Response+ object being used
8
- def response_object
9
- $RESPONSE
10
- end
11
-
12
- # The +Waitress::Request+ object being used
13
- def request_object
14
- $REQUEST
15
- end
16
-
17
- # Prepare the Kernel, by linking global variables
18
- def kernel_prepare
19
- $METHOD = get_method
20
- $HEADERS = get_headers
21
- $PATH = get_path
22
- $URI = get_uri
23
- $BODY = get_body
24
- end
25
-
26
- # Automatically load a library header into this file in the form of HTML.
27
- # This will load a library in the VHost's libs/ folder, or any lib defined in the
28
- # VHost's config.rb file with the name given. JS libraries will be linked with the
29
- # <script> tag, whilst css files will be linked with the <link rel="stylesheet">
30
- # tag. This is the recommended way of handling library loading.
31
- # Params:
32
- # +name+:: The name of the lib (the filename), or the name of the library as bound
33
- # in the config.rb file.
34
- def lib name
35
- name = name.to_sym
36
- type = $VHOST.libraries[name][:type]
37
- libhome = $VHOST.liburi
38
- if type == :js
39
- echo "<script type='text/javascript' src='/#{libhome}/#{name}'></script>"
40
- elsif type == :css
41
- echo "<link rel='stylesheet' href='/#{libhome}/#{name}'></link>"
42
- end
43
- end
44
-
45
- # Automatically load a Library Combo into this file. This will consecutively load
46
- # all the libraries bound to the combination with the given name as defined in the
47
- # VHost's config.rb file. This will call lib() for each of these libraries.
48
- # Params:
49
- # +name+:: The name of the combo to load
50
- def combo name
51
- name = name.to_sym
52
- combo_arr = $VHOST.combos[name]
53
- combo_arr.each { |n| lib(n) }
54
- end
55
-
56
- # Include another .wrb, .rb or any other file in the load path of the VHost into this
57
- # file. If this file is .wrb or .rb, it will be evaluated. If it is another type of file
58
- # (e.g. html), it will be directly echoed to the output buffer
59
- # Params:
60
- # +filename+:: The name of the file, relative to the loadpath
61
- def includes filename
62
- Waitress::Chef.include_file filename
63
- end
64
-
65
- # Include another .wrb, .rb or any other file in this file. If this file is
66
- # .wrb or .rb, it will be evaluated. If it is another type of file
67
- # (e.g. html), it will be directly echoed to the output buffer
68
- # Params:
69
- # +filename+:: The absolute filename of the file to load, anywhere in the filesystem
70
- def includes_file filename
71
- Waitress::Chef.include_absfile filename
72
- end
73
-
74
- # The configuration for the VHost. As described in the +Waitress::VHost+ class,
75
- # this data is set in the config.rb file and is then read out later by the
76
- # server. Use this to configure constants such as Social Media links, and other details
77
- def config
78
- $VHOST.config
79
- end
80
-
81
- # Returns a Hash of the GET query of the request. This may be an empty array
82
- # if querystring was present
83
- def get
84
- request_object.get_query
85
- end
86
-
87
- # Returns a Hash of the POST query of the request. This may be an empty array
88
- # if the body is not a valid querystring, or an exception raised if there was
89
- # an error in parsing.
90
- def post
91
- request_object.post_query
92
- end
93
-
94
- # Get a header from the HTTP Request. This will fetch the header by the given
95
- # name from the request object. Keep in mind that in requests, Headers are fully
96
- # capitalized and any hyphens replaced with underscores (e.g. Content-Type becomes
97
- # CONTENT_TYPE)
98
- def get_header name
99
- request_object.headers[name]
100
- end
101
-
102
- # Return the full list of headers available in the request object.
103
- def get_headers
104
- request_object.headers
105
- end
106
-
107
- # Returns the HTTP method that was used to retrieve this page (GET, POST, UPDATE,
108
- # DELETE, PUT, etc)
109
- def get_method
110
- request_object.method
111
- end
112
-
113
- # Get the path of this request. This is after a URL rewrite, and does not contain
114
- # a querystring. Be careful with these, as they start with a "/" and if not joined
115
- # correctly can cause issues in the root of your filesystem (use File.join) if you
116
- # plan to use this
117
- def get_path
118
- request_object.path
119
- end
120
-
121
- # Get the URI of this request. Unlike the path, the URI is not modified after a rewrite,
122
- # and does contain a querystring. Use this if you want the *original* path and query
123
- # of the request before it was rewritten
124
- def get_uri
125
- request_object.uri
126
- end
127
-
128
- # Get the request body. In most cases, this will be blank, but for POST requests it may
129
- # contain a querystring, and for PUT and UPDATE methods it may contain other data
130
- def get_body
131
- request_object.body
132
- end
133
-
134
- # Get the querystring object as a string before it is parsed
135
- def get_querystring
136
- request_object.querystring
137
- end
138
-
139
- # Set a response header. This will be joined when writing the response with the delimiter ": "
140
- # as in regular HTTP Protocol fashion.
141
- # Params:
142
- # +name+:: The name of the header, e.g. "Content-Type"
143
- # +value+:: The value of the header, e.g. "text/html"
144
- def set_header name, value
145
- response_object.header name, value
146
- end
147
-
148
- # Set the content-type of the response. This is a shortcut to the Content-Type
149
- # header and takes the full content-type (not fileextension) as an argument
150
- # Params:
151
- # +raw_type+:: The mime type of the content, e.g. "text/html"
152
- def set_content_type raw_type
153
- response_object.mime_raw raw_type
154
- end
155
-
156
- # Set the content-type of the response. This is a shortcut to the Content-Type
157
- # header, and will also lookup the fileextension in the +Waitress::Util+ mime-type
158
- # lookup.
159
- # Params:
160
- # +extension+:: The file extension to map to a mimetype, e.g. ".html"
161
- def file_ext extension
162
- response_object.mime extension
163
- end
164
-
165
- # Write a string to the output buffer. This will write directly to the body of the
166
- # response, similar to what 'print()' does for STDOUT. Use this to write data to the
167
- # output stream
168
- def echo obj
169
- str = obj.to_s
170
- write str
171
- end
172
-
173
- # Write a string to the output buffer, followed by a newline. Similar to echo(),
174
- # this will write to the output buffer, but also adds a "\n". This does to the
175
- # client output as 'puts()' does to STDOUT. Use this to write data to the output
176
- # stream
177
- def println obj
178
- echo(obj.to_s + "\n")
179
- end
180
-
181
- # Write a set of bytes directly to the output stream. Use this if you don't want
182
- # to cast to a string as echo() and println() do.
183
- def write bytes
184
- r = response_object
185
- r.body "" if r.body_io.nil?
186
- r.body_io.write bytes
187
- end
188
-
189
- end
1
+ # The Kernel Module provides global methods that will provide the 'builtins' for .wrb files
2
+ # and handlers. This is used to prevent verbose access of a namespace like Waitress::Global,
3
+ # and instead provide them here. Because requests are handled in new Processes, these values
4
+ # will change in each request and will not interfere.
5
+ module ::Kernel
6
+
7
+ # The +Waitress::Response+ object being used
8
+ def response_object
9
+ $RESPONSE
10
+ end
11
+
12
+ # The +Waitress::Request+ object being used
13
+ def request_object
14
+ $REQUEST
15
+ end
16
+
17
+ # Prepare the Kernel, by linking global variables
18
+ def kernel_prepare
19
+ $METHOD = get_method
20
+ $HEADERS = get_headers
21
+ $PATH = get_path
22
+ $URI = get_uri
23
+ $BODY = get_body
24
+ end
25
+
26
+ # Automatically load a library header into this file in the form of HTML.
27
+ # This will load a library in the VHost's libs/ folder, or any lib defined in the
28
+ # VHost's config.rb file with the name given. JS libraries will be linked with the
29
+ # <script> tag, whilst css files will be linked with the <link rel="stylesheet">
30
+ # tag. This is the recommended way of handling library loading.
31
+ # Params:
32
+ # +name+:: The name of the lib (the filename), or the name of the library as bound
33
+ # in the config.rb file.
34
+ def lib name
35
+ name = name.to_sym
36
+ type = $VHOST.libraries[name][:type]
37
+ libhome = $VHOST.liburi
38
+ if type == :js
39
+ echo "<script type='text/javascript' src='/#{libhome}/#{name}'></script>"
40
+ elsif type == :css
41
+ echo "<link rel='stylesheet' href='/#{libhome}/#{name}'></link>"
42
+ end
43
+ end
44
+
45
+ # Automatically load a Library Combo into this file. This will consecutively load
46
+ # all the libraries bound to the combination with the given name as defined in the
47
+ # VHost's config.rb file. This will call lib() for each of these libraries.
48
+ # Params:
49
+ # +name+:: The name of the combo to load
50
+ def combo name
51
+ name = name.to_sym
52
+ combo_arr = $VHOST.combos[name]
53
+ combo_arr.each { |n| lib(n) }
54
+ end
55
+
56
+ # Include another .wrb, .rb or any other file in the load path of the VHost into this
57
+ # file. If this file is .wrb or .rb, it will be evaluated. If it is another type of file
58
+ # (e.g. html), it will be directly echoed to the output buffer
59
+ # Params:
60
+ # +filename+:: The name of the file, relative to the loadpath
61
+ def includes filename
62
+ Waitress::Chef.include_file filename
63
+ end
64
+
65
+ # Include another .wrb, .rb or any other file in this file. If this file is
66
+ # .wrb or .rb, it will be evaluated. If it is another type of file
67
+ # (e.g. html), it will be directly echoed to the output buffer
68
+ # Params:
69
+ # +filename+:: The absolute filename of the file to load, anywhere in the filesystem
70
+ def includes_file filename
71
+ Waitress::Chef.include_absfile filename
72
+ end
73
+
74
+ # The configuration for the VHost. As described in the +Waitress::VHost+ class,
75
+ # this data is set in the config.rb file and is then read out later by the
76
+ # server. Use this to configure constants such as Social Media links, and other details
77
+ def config
78
+ $VHOST.config
79
+ end
80
+
81
+ # Returns a Hash of the GET query of the request. This may be an empty array
82
+ # if querystring was present
83
+ def get
84
+ request_object.get_query
85
+ end
86
+
87
+ # Returns a Hash of the POST query of the request. This may be an empty array
88
+ # if the body is not a valid querystring, or an exception raised if there was
89
+ # an error in parsing.
90
+ def post
91
+ request_object.post_query
92
+ end
93
+
94
+ # Get a header from the HTTP Request. This will fetch the header by the given
95
+ # name from the request object. Keep in mind that in requests, Headers are fully
96
+ # capitalized and any hyphens replaced with underscores (e.g. Content-Type becomes
97
+ # CONTENT_TYPE)
98
+ def get_header name
99
+ request_object.headers[name]
100
+ end
101
+
102
+ # Return the full list of headers available in the request object.
103
+ def get_headers
104
+ request_object.headers
105
+ end
106
+
107
+ # Returns the HTTP method that was used to retrieve this page (GET, POST, UPDATE,
108
+ # DELETE, PUT, etc)
109
+ def get_method
110
+ request_object.method
111
+ end
112
+
113
+ # Get the path of this request. This is after a URL rewrite, and does not contain
114
+ # a querystring. Be careful with these, as they start with a "/" and if not joined
115
+ # correctly can cause issues in the root of your filesystem (use File.join) if you
116
+ # plan to use this
117
+ def get_path
118
+ request_object.path
119
+ end
120
+
121
+ # Get the URI of this request. Unlike the path, the URI is not modified after a rewrite,
122
+ # and does contain a querystring. Use this if you want the *original* path and query
123
+ # of the request before it was rewritten
124
+ def get_uri
125
+ request_object.uri
126
+ end
127
+
128
+ # Get the request body. In most cases, this will be blank, but for POST requests it may
129
+ # contain a querystring, and for PUT and UPDATE methods it may contain other data
130
+ def get_body
131
+ request_object.body
132
+ end
133
+
134
+ # Get the querystring object as a string before it is parsed
135
+ def get_querystring
136
+ request_object.querystring
137
+ end
138
+
139
+ # Set a response header. This will be joined when writing the response with the delimiter ": "
140
+ # as in regular HTTP Protocol fashion.
141
+ # Params:
142
+ # +name+:: The name of the header, e.g. "Content-Type"
143
+ # +value+:: The value of the header, e.g. "text/html"
144
+ def set_header name, value
145
+ response_object.header name, value
146
+ end
147
+
148
+ # Set the content-type of the response. This is a shortcut to the Content-Type
149
+ # header and takes the full content-type (not fileextension) as an argument
150
+ # Params:
151
+ # +raw_type+:: The mime type of the content, e.g. "text/html"
152
+ def set_content_type raw_type
153
+ response_object.mime_raw raw_type
154
+ end
155
+
156
+ # Set the content-type of the response. This is a shortcut to the Content-Type
157
+ # header, and will also lookup the fileextension in the +Waitress::Util+ mime-type
158
+ # lookup.
159
+ # Params:
160
+ # +extension+:: The file extension to map to a mimetype, e.g. ".html"
161
+ def file_ext extension
162
+ response_object.mime extension
163
+ end
164
+
165
+ # Write a string to the output buffer. This will write directly to the body of the
166
+ # response, similar to what 'print()' does for STDOUT. Use this to write data to the
167
+ # output stream
168
+ def echo obj
169
+ str = obj.to_s
170
+ write str
171
+ end
172
+
173
+ # Write a string to the output buffer, followed by a newline. Similar to echo(),
174
+ # this will write to the output buffer, but also adds a "\n". This does to the
175
+ # client output as 'puts()' does to STDOUT. Use this to write data to the output
176
+ # stream
177
+ def println obj
178
+ echo(obj.to_s + "\n")
179
+ end
180
+
181
+ # Write a set of bytes directly to the output stream. Use this if you don't want
182
+ # to cast to a string as echo() and println() do.
183
+ def write bytes
184
+ r = response_object
185
+ r.body "" if r.body_io.nil?
186
+ r.body_io.write bytes
187
+ end
188
+
189
+ end
@@ -1,60 +1,60 @@
1
- module Waitress
2
- # A lot of this class uses methods from Rack::QueryParser in order to Parse
3
- # a given QueryString into a Hash of key/value pairs
4
- class QueryParser
5
- require 'uri'
6
-
7
- DEFAULT_SEP = /[&;] */n
8
-
9
- # Unescape a HTTP URL to regular text. e.g. %20 becomes a space (" ")
10
- def self.unescape str, enc=Encoding::UTF_8
11
- URI.decode_www_form_component(str, enc)
12
- end
13
-
14
- # Parse the given QueryString into a hash of key/value pairs
15
- def self.parse qs
16
- return {} if qs.nil? || qs.empty?
17
- results = {}
18
- (qs || '').split(DEFAULT_SEP).each do |p|
19
- k, v = p.split('='.freeze, 2).map! { |s| unescape(s) }
20
-
21
- normalize results, k, v
22
- end
23
- results
24
- end
25
-
26
- def self.normalize hash, name, v
27
- name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
28
- k = $1 || ''
29
- after = $' || ''
30
-
31
- return if k.empty?
32
-
33
- if after == ""
34
- hash[k] = v
35
- elsif after == "["
36
- hash[name] = v
37
- elsif after == "[]"
38
- hash[k] ||= []
39
- raise TypeError, "expected Array (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Array)
40
- hash[k] << v
41
- elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
42
- child_key = $1
43
- hash[k] ||= []
44
- raise TypeError, "expected Array (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Array)
45
- if hash[k].last.is_a?(Hash) && !hash[k].last.key?(child_key)
46
- normalize(hash[k].last, child_key, v)
47
- else
48
- hash[k] << normalize({}, child_key, v)
49
- end
50
- else
51
- hash[k] ||= {}
52
- raise TypeError, "expected Hash (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Hash)
53
- hash[k] = normalize(hash[k], after, v)
54
- end
55
-
56
- hash
57
- end
58
-
59
- end
60
- end
1
+ module Waitress
2
+ # A lot of this class uses methods from Rack::QueryParser in order to Parse
3
+ # a given QueryString into a Hash of key/value pairs
4
+ class QueryParser
5
+ require 'uri'
6
+
7
+ DEFAULT_SEP = /[&;] */n
8
+
9
+ # Unescape a HTTP URL to regular text. e.g. %20 becomes a space (" ")
10
+ def self.unescape str, enc=Encoding::UTF_8
11
+ URI.decode_www_form_component(str, enc)
12
+ end
13
+
14
+ # Parse the given QueryString into a hash of key/value pairs
15
+ def self.parse qs
16
+ return {} if qs.nil? || qs.empty?
17
+ results = {}
18
+ (qs || '').split(DEFAULT_SEP).each do |p|
19
+ k, v = p.split('='.freeze, 2).map! { |s| unescape(s) }
20
+
21
+ normalize results, k, v
22
+ end
23
+ results
24
+ end
25
+
26
+ def self.normalize hash, name, v
27
+ name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
28
+ k = $1 || ''
29
+ after = $' || ''
30
+
31
+ return if k.empty?
32
+
33
+ if after == ""
34
+ hash[k] = v
35
+ elsif after == "["
36
+ hash[name] = v
37
+ elsif after == "[]"
38
+ hash[k] ||= []
39
+ raise TypeError, "expected Array (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Array)
40
+ hash[k] << v
41
+ elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
42
+ child_key = $1
43
+ hash[k] ||= []
44
+ raise TypeError, "expected Array (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Array)
45
+ if hash[k].last.is_a?(Hash) && !hash[k].last.key?(child_key)
46
+ normalize(hash[k].last, child_key, v)
47
+ else
48
+ hash[k] << normalize({}, child_key, v)
49
+ end
50
+ else
51
+ hash[k] ||= {}
52
+ raise TypeError, "expected Hash (got #{hash[k].class.name}) for param `#{k}'" unless hash[k].is_a?(Hash)
53
+ hash[k] = normalize(hash[k], after, v)
54
+ end
55
+
56
+ hash
57
+ end
58
+
59
+ end
60
+ end