waitress-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +21 -0
  4. data/Rakefile +4 -0
  5. data/bin/waitress +22 -0
  6. data/ext/Thanks.md +1 -0
  7. data/ext/waitress_http11/ext_help.h +15 -0
  8. data/ext/waitress_http11/extconf.rb +6 -0
  9. data/ext/waitress_http11/http11.c +532 -0
  10. data/ext/waitress_http11/http11_parser.c +1216 -0
  11. data/ext/waitress_http11/http11_parser.h +49 -0
  12. data/ext/waitress_http11/http11_parser.java.rl +171 -0
  13. data/ext/waitress_http11/http11_parser.rl +165 -0
  14. data/ext/waitress_http11/http11_parser_common.rl +55 -0
  15. data/ext/waitress_http11/http11_wrb_parser.h +83 -0
  16. data/lib/waitress.rb +98 -0
  17. data/lib/waitress/chef.rb +110 -0
  18. data/lib/waitress/configure.rb +116 -0
  19. data/lib/waitress/handlers/dirhandler.rb +39 -0
  20. data/lib/waitress/handlers/handler.rb +57 -0
  21. data/lib/waitress/handlers/handler404.rb +25 -0
  22. data/lib/waitress/handlers/libhandler.rb +58 -0
  23. data/lib/waitress/kernel.rb +182 -0
  24. data/lib/waitress/parse/query.rb +60 -0
  25. data/lib/waitress/request.rb +45 -0
  26. data/lib/waitress/resources/default_config.rb +52 -0
  27. data/lib/waitress/resources/http/404.html +18 -0
  28. data/lib/waitress/resources/http/css/hack.css +37 -0
  29. data/lib/waitress/resources/http/css/waitress.css +57 -0
  30. data/lib/waitress/resources/http/fonts/eot/latin/hack-bold-latin-webfont.eot +0 -0
  31. data/lib/waitress/resources/http/fonts/eot/latin/hack-bolditalic-latin-webfont.eot +0 -0
  32. data/lib/waitress/resources/http/fonts/eot/latin/hack-italic-latin-webfont.eot +0 -0
  33. data/lib/waitress/resources/http/fonts/eot/latin/hack-regular-latin-webfont.eot +0 -0
  34. data/lib/waitress/resources/http/fonts/svg/latin/hack-bold-latin-webfont.svg +241 -0
  35. data/lib/waitress/resources/http/fonts/svg/latin/hack-bolditalic-latin-webfont.svg +241 -0
  36. data/lib/waitress/resources/http/fonts/svg/latin/hack-italic-latin-webfont.svg +241 -0
  37. data/lib/waitress/resources/http/fonts/svg/latin/hack-regular-latin-webfont.svg +241 -0
  38. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bold-latin-webfont.ttf +0 -0
  39. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-bolditalic-latin-webfont.ttf +0 -0
  40. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-italic-latin-webfont.ttf +0 -0
  41. data/lib/waitress/resources/http/fonts/web-ttf/latin/hack-regular-latin-webfont.ttf +0 -0
  42. data/lib/waitress/resources/http/fonts/woff/latin/hack-bold-latin-webfont.woff +0 -0
  43. data/lib/waitress/resources/http/fonts/woff/latin/hack-bolditalic-latin-webfont.woff +0 -0
  44. data/lib/waitress/resources/http/fonts/woff/latin/hack-italic-latin-webfont.woff +0 -0
  45. data/lib/waitress/resources/http/fonts/woff/latin/hack-regular-latin-webfont.woff +0 -0
  46. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bold-latin-webfont.woff2 +0 -0
  47. data/lib/waitress/resources/http/fonts/woff2/latin/hack-bolditalic-latin-webfont.woff2 +0 -0
  48. data/lib/waitress/resources/http/fonts/woff2/latin/hack-italic-latin-webfont.woff2 +0 -0
  49. data/lib/waitress/resources/http/fonts/woff2/latin/hack-regular-latin-webfont.woff2 +0 -0
  50. data/lib/waitress/resources/http/img/404.png +0 -0
  51. data/lib/waitress/resources/http/index.html +15 -0
  52. data/lib/waitress/response.rb +104 -0
  53. data/lib/waitress/server.rb +115 -0
  54. data/lib/waitress/util.rb +713 -0
  55. data/lib/waitress/version.rb +3 -0
  56. data/lib/waitress/vhost.rb +217 -0
  57. data/lib/waitress_http11.so +0 -0
  58. data/waitress-core.gemspec +27 -0
  59. metadata +187 -0
@@ -0,0 +1,3 @@
1
+ module Waitress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +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 lib_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
Binary file
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'waitress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "waitress-core"
8
+ spec.version = Waitress::VERSION
9
+ spec.authors = ["Jaci Brunning"]
10
+ spec.email = ["jaci.brunning@gmail.com"]
11
+
12
+ spec.summary = %q{Waitress is a lightweight, fast Ruby Web Server with the ability to serve dynamic webpages, manage libraries and support for virtual hosts and much more}
13
+ spec.homepage = "http://github.com/JacisNonsense/Waitress"
14
+
15
+ spec.bindir = "bin"
16
+ spec.files = Dir.glob("lib/**/*") + ['Rakefile', 'waitress-core.gemspec', 'Gemfile', 'LICENSE'] + Dir.glob("ext/**/*")
17
+ spec.executables = ["waitress"]
18
+ spec.require_paths = ["lib"]
19
+ spec.extensions << "ext/waitress_http11/extconf.rb"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rake-compiler"
24
+ spec.add_dependency "Go.rb", ">= 0.3.0"
25
+ spec.add_dependency "scon"
26
+ spec.add_dependency "configfile"
27
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waitress-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jaci Brunning
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: Go.rb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: scon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: configfile
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - jaci.brunning@gmail.com
100
+ executables:
101
+ - waitress
102
+ extensions:
103
+ - ext/waitress_http11/extconf.rb
104
+ extra_rdoc_files: []
105
+ files:
106
+ - Gemfile
107
+ - LICENSE
108
+ - Rakefile
109
+ - bin/waitress
110
+ - ext/Thanks.md
111
+ - ext/waitress_http11/ext_help.h
112
+ - ext/waitress_http11/extconf.rb
113
+ - ext/waitress_http11/http11.c
114
+ - ext/waitress_http11/http11_parser.c
115
+ - ext/waitress_http11/http11_parser.h
116
+ - ext/waitress_http11/http11_parser.java.rl
117
+ - ext/waitress_http11/http11_parser.rl
118
+ - ext/waitress_http11/http11_parser_common.rl
119
+ - ext/waitress_http11/http11_wrb_parser.h
120
+ - lib/waitress.rb
121
+ - lib/waitress/chef.rb
122
+ - lib/waitress/configure.rb
123
+ - lib/waitress/handlers/dirhandler.rb
124
+ - lib/waitress/handlers/handler.rb
125
+ - lib/waitress/handlers/handler404.rb
126
+ - lib/waitress/handlers/libhandler.rb
127
+ - lib/waitress/kernel.rb
128
+ - lib/waitress/parse/query.rb
129
+ - lib/waitress/request.rb
130
+ - lib/waitress/resources/default_config.rb
131
+ - lib/waitress/resources/http/404.html
132
+ - lib/waitress/resources/http/css/hack.css
133
+ - lib/waitress/resources/http/css/waitress.css
134
+ - lib/waitress/resources/http/fonts/eot/latin/hack-bold-latin-webfont.eot
135
+ - lib/waitress/resources/http/fonts/eot/latin/hack-bolditalic-latin-webfont.eot
136
+ - lib/waitress/resources/http/fonts/eot/latin/hack-italic-latin-webfont.eot
137
+ - lib/waitress/resources/http/fonts/eot/latin/hack-regular-latin-webfont.eot
138
+ - lib/waitress/resources/http/fonts/svg/latin/hack-bold-latin-webfont.svg
139
+ - lib/waitress/resources/http/fonts/svg/latin/hack-bolditalic-latin-webfont.svg
140
+ - lib/waitress/resources/http/fonts/svg/latin/hack-italic-latin-webfont.svg
141
+ - lib/waitress/resources/http/fonts/svg/latin/hack-regular-latin-webfont.svg
142
+ - lib/waitress/resources/http/fonts/web-ttf/latin/hack-bold-latin-webfont.ttf
143
+ - lib/waitress/resources/http/fonts/web-ttf/latin/hack-bolditalic-latin-webfont.ttf
144
+ - lib/waitress/resources/http/fonts/web-ttf/latin/hack-italic-latin-webfont.ttf
145
+ - lib/waitress/resources/http/fonts/web-ttf/latin/hack-regular-latin-webfont.ttf
146
+ - lib/waitress/resources/http/fonts/woff/latin/hack-bold-latin-webfont.woff
147
+ - lib/waitress/resources/http/fonts/woff/latin/hack-bolditalic-latin-webfont.woff
148
+ - lib/waitress/resources/http/fonts/woff/latin/hack-italic-latin-webfont.woff
149
+ - lib/waitress/resources/http/fonts/woff/latin/hack-regular-latin-webfont.woff
150
+ - lib/waitress/resources/http/fonts/woff2/latin/hack-bold-latin-webfont.woff2
151
+ - lib/waitress/resources/http/fonts/woff2/latin/hack-bolditalic-latin-webfont.woff2
152
+ - lib/waitress/resources/http/fonts/woff2/latin/hack-italic-latin-webfont.woff2
153
+ - lib/waitress/resources/http/fonts/woff2/latin/hack-regular-latin-webfont.woff2
154
+ - lib/waitress/resources/http/img/404.png
155
+ - lib/waitress/resources/http/index.html
156
+ - lib/waitress/response.rb
157
+ - lib/waitress/server.rb
158
+ - lib/waitress/util.rb
159
+ - lib/waitress/version.rb
160
+ - lib/waitress/vhost.rb
161
+ - lib/waitress_http11.so
162
+ - waitress-core.gemspec
163
+ homepage: http://github.com/JacisNonsense/Waitress
164
+ licenses: []
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.5
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Waitress is a lightweight, fast Ruby Web Server with the ability to serve
186
+ dynamic webpages, manage libraries and support for virtual hosts and much more
187
+ test_files: []