homura-runtime 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/homura/runtime/version.rb +1 -1
  4. data/vendor/rack/auth/abstract/handler.rb +41 -0
  5. data/vendor/rack/auth/abstract/request.rb +51 -0
  6. data/vendor/rack/auth/basic.rb +58 -0
  7. data/vendor/rack/bad_request.rb +8 -0
  8. data/vendor/rack/body_proxy.rb +63 -0
  9. data/vendor/rack/builder.rb +315 -0
  10. data/vendor/rack/cascade.rb +67 -0
  11. data/vendor/rack/common_logger.rb +94 -0
  12. data/vendor/rack/conditional_get.rb +87 -0
  13. data/vendor/rack/config.rb +22 -0
  14. data/vendor/rack/constants.rb +68 -0
  15. data/vendor/rack/content_length.rb +34 -0
  16. data/vendor/rack/content_type.rb +33 -0
  17. data/vendor/rack/deflater.rb +159 -0
  18. data/vendor/rack/directory.rb +210 -0
  19. data/vendor/rack/etag.rb +71 -0
  20. data/vendor/rack/events.rb +172 -0
  21. data/vendor/rack/files.rb +224 -0
  22. data/vendor/rack/head.rb +25 -0
  23. data/vendor/rack/headers.rb +238 -0
  24. data/vendor/rack/lint.rb +1000 -0
  25. data/vendor/rack/lock.rb +29 -0
  26. data/vendor/rack/media_type.rb +42 -0
  27. data/vendor/rack/method_override.rb +56 -0
  28. data/vendor/rack/mime.rb +694 -0
  29. data/vendor/rack/mock.rb +3 -0
  30. data/vendor/rack/mock_request.rb +161 -0
  31. data/vendor/rack/mock_response.rb +147 -0
  32. data/vendor/rack/multipart/generator.rb +99 -0
  33. data/vendor/rack/multipart/parser.rb +586 -0
  34. data/vendor/rack/multipart/uploaded_file.rb +82 -0
  35. data/vendor/rack/multipart.rb +77 -0
  36. data/vendor/rack/null_logger.rb +48 -0
  37. data/vendor/rack/protection/authenticity_token.rb +256 -0
  38. data/vendor/rack/protection/base.rb +140 -0
  39. data/vendor/rack/protection/content_security_policy.rb +80 -0
  40. data/vendor/rack/protection/cookie_tossing.rb +77 -0
  41. data/vendor/rack/protection/escaped_params.rb +93 -0
  42. data/vendor/rack/protection/form_token.rb +25 -0
  43. data/vendor/rack/protection/frame_options.rb +39 -0
  44. data/vendor/rack/protection/http_origin.rb +43 -0
  45. data/vendor/rack/protection/ip_spoofing.rb +27 -0
  46. data/vendor/rack/protection/json_csrf.rb +60 -0
  47. data/vendor/rack/protection/path_traversal.rb +45 -0
  48. data/vendor/rack/protection/referrer_policy.rb +27 -0
  49. data/vendor/rack/protection/remote_referrer.rb +22 -0
  50. data/vendor/rack/protection/remote_token.rb +24 -0
  51. data/vendor/rack/protection/session_hijacking.rb +37 -0
  52. data/vendor/rack/protection/strict_transport.rb +41 -0
  53. data/vendor/rack/protection/version.rb +7 -0
  54. data/vendor/rack/protection/xss_header.rb +27 -0
  55. data/vendor/rack/protection.rb +58 -0
  56. data/vendor/rack/query_parser.rb +261 -0
  57. data/vendor/rack/recursive.rb +66 -0
  58. data/vendor/rack/reloader.rb +112 -0
  59. data/vendor/rack/request.rb +818 -0
  60. data/vendor/rack/response.rb +403 -0
  61. data/vendor/rack/rewindable_input.rb +116 -0
  62. data/vendor/rack/runtime.rb +35 -0
  63. data/vendor/rack/sendfile.rb +197 -0
  64. data/vendor/rack/session/abstract/id.rb +533 -0
  65. data/vendor/rack/session/constants.rb +13 -0
  66. data/vendor/rack/session/cookie.rb +292 -0
  67. data/vendor/rack/session/encryptor.rb +415 -0
  68. data/vendor/rack/session/pool.rb +76 -0
  69. data/vendor/rack/session/version.rb +10 -0
  70. data/vendor/rack/session.rb +12 -0
  71. data/vendor/rack/show_exceptions.rb +433 -0
  72. data/vendor/rack/show_status.rb +121 -0
  73. data/vendor/rack/static.rb +188 -0
  74. data/vendor/rack/tempfile_reaper.rb +44 -0
  75. data/vendor/rack/urlmap.rb +99 -0
  76. data/vendor/rack/utils.rb +631 -0
  77. data/vendor/rack/version.rb +17 -0
  78. data/vendor/rack.rb +66 -0
  79. metadata +76 -1
@@ -0,0 +1,188 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'files'
5
+ require_relative 'mime'
6
+
7
+ module Rack
8
+
9
+ # The Rack::Static middleware intercepts requests for static files
10
+ # (javascript files, images, stylesheets, etc) based on the url prefixes or
11
+ # route mappings passed in the options, and serves them using a Rack::Files
12
+ # object. This allows a Rack stack to serve both static and dynamic content.
13
+ #
14
+ # Examples:
15
+ #
16
+ # Serve all requests beginning with /media from the "media" folder located
17
+ # in the current directory (ie media/*):
18
+ #
19
+ # use Rack::Static, :urls => ["/media"]
20
+ #
21
+ # Same as previous, but instead of returning 404 for missing files under
22
+ # /media, call the next middleware:
23
+ #
24
+ # use Rack::Static, :urls => ["/media"], :cascade => true
25
+ #
26
+ # Serve all requests beginning with /css or /images from the folder "public"
27
+ # in the current directory (ie public/css/* and public/images/*):
28
+ #
29
+ # use Rack::Static, :urls => ["/css", "/images"], :root => "public"
30
+ #
31
+ # Serve all requests to / with "index.html" from the folder "public" in the
32
+ # current directory (ie public/index.html):
33
+ #
34
+ # use Rack::Static, :urls => {"/" => 'index.html'}, :root => 'public'
35
+ #
36
+ # Serve all requests normally from the folder "public" in the current
37
+ # directory but uses index.html as default route for "/"
38
+ #
39
+ # use Rack::Static, :urls => [""], :root => 'public', :index =>
40
+ # 'index.html'
41
+ #
42
+ # Set custom HTTP Headers for based on rules:
43
+ #
44
+ # use Rack::Static, :root => 'public',
45
+ # :header_rules => [
46
+ # [rule, {header_field => content, header_field => content}],
47
+ # [rule, {header_field => content}]
48
+ # ]
49
+ #
50
+ # Rules for selecting files:
51
+ #
52
+ # 1) All files
53
+ # Provide the :all symbol
54
+ # :all => Matches every file
55
+ #
56
+ # 2) Folders
57
+ # Provide the folder path as a string
58
+ # '/folder' or '/folder/subfolder' => Matches files in a certain folder
59
+ #
60
+ # 3) File Extensions
61
+ # Provide the file extensions as an array
62
+ # ['css', 'js'] or %w(css js) => Matches files ending in .css or .js
63
+ #
64
+ # 4) Regular Expressions / Regexp
65
+ # Provide a regular expression
66
+ # %r{\.(?:css|js)\z} => Matches files ending in .css or .js
67
+ # /\.(?:eot|ttf|otf|woff2|woff|svg)\z/ => Matches files ending in
68
+ # the most common web font formats (.eot, .ttf, .otf, .woff2, .woff, .svg)
69
+ # Note: This Regexp is available as a shortcut, using the :fonts rule
70
+ #
71
+ # 5) Font Shortcut
72
+ # Provide the :fonts symbol
73
+ # :fonts => Uses the Regexp rule stated right above to match all common web font endings
74
+ #
75
+ # Rule Ordering:
76
+ # Rules are applied in the order that they are provided.
77
+ # List rather general rules above special ones.
78
+ #
79
+ # Complete example use case including HTTP header rules:
80
+ #
81
+ # use Rack::Static, :root => 'public',
82
+ # :header_rules => [
83
+ # # Cache all static files in public caches (e.g. Rack::Cache)
84
+ # # as well as in the browser
85
+ # [:all, {'cache-control' => 'public, max-age=31536000'}],
86
+ #
87
+ # # Provide web fonts with cross-origin access-control-headers
88
+ # # Firefox requires this when serving assets using a Content Delivery Network
89
+ # [:fonts, {'access-control-allow-origin' => '*'}]
90
+ # ]
91
+ #
92
+ class Static
93
+ def initialize(app, options = {})
94
+ @app = app
95
+ @urls = options[:urls] || ["/favicon.ico"]
96
+ @index = options[:index]
97
+ @gzip = options[:gzip]
98
+ @cascade = options[:cascade]
99
+ root = options[:root] || Dir.pwd
100
+
101
+ # HTTP Headers
102
+ @header_rules = options[:header_rules] || []
103
+ # Allow for legacy :cache_control option while prioritizing global header_rules setting
104
+ @header_rules.unshift([:all, { CACHE_CONTROL => options[:cache_control] }]) if options[:cache_control]
105
+
106
+ @file_server = Rack::Files.new(root)
107
+ end
108
+
109
+ def add_index_root?(path)
110
+ @index && route_file(path) && path.end_with?('/')
111
+ end
112
+
113
+ def overwrite_file_path(path)
114
+ @urls.kind_of?(Hash) && @urls.key?(path) || add_index_root?(path)
115
+ end
116
+
117
+ def route_file(path)
118
+ @urls.kind_of?(Array) && @urls.any? { |url| path.index(url) == 0 }
119
+ end
120
+
121
+ def can_serve(path)
122
+ route_file(path) || overwrite_file_path(path)
123
+ end
124
+
125
+ def call(env)
126
+ path = env[PATH_INFO]
127
+ actual_path = Utils.clean_path_info(Utils.unescape_path(path))
128
+
129
+ if can_serve(actual_path)
130
+ if overwrite_file_path(path)
131
+ env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
132
+ elsif @gzip && env['HTTP_ACCEPT_ENCODING'] && /\bgzip\b/.match?(env['HTTP_ACCEPT_ENCODING'])
133
+ path = env[PATH_INFO]
134
+ env[PATH_INFO] += '.gz'
135
+ response = @file_server.call(env)
136
+ env[PATH_INFO] = path
137
+
138
+ if response[0] == 404
139
+ response = nil
140
+ elsif response[0] == 304
141
+ # Do nothing, leave headers as is
142
+ else
143
+ response[1][CONTENT_TYPE] = Mime.mime_type(::File.extname(path), 'text/plain')
144
+ response[1]['content-encoding'] = 'gzip'
145
+ end
146
+ end
147
+
148
+ path = env[PATH_INFO]
149
+ response ||= @file_server.call(env)
150
+
151
+ if @cascade && response[0] == 404
152
+ return @app.call(env)
153
+ end
154
+
155
+ headers = response[1]
156
+ applicable_rules(path).each do |rule, new_headers|
157
+ new_headers.each { |field, content| headers[field] = content }
158
+ end
159
+
160
+ response
161
+ else
162
+ @app.call(env)
163
+ end
164
+ end
165
+
166
+ # Convert HTTP header rules to HTTP headers
167
+ def applicable_rules(path)
168
+ @header_rules.find_all do |rule, new_headers|
169
+ case rule
170
+ when :all
171
+ true
172
+ when :fonts
173
+ /\.(?:ttf|otf|eot|woff2|woff|svg)\z/.match?(path)
174
+ when String
175
+ path = ::Rack::Utils.unescape(path)
176
+ path.start_with?(rule) || path.start_with?('/' + rule)
177
+ when Array
178
+ /\.(#{rule.join('|')})\z/.match?(path)
179
+ when Regexp
180
+ rule.match?(path)
181
+ else
182
+ false
183
+ end
184
+ end
185
+ end
186
+
187
+ end
188
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'body_proxy'
5
+
6
+ module Rack
7
+
8
+ # Middleware tracks and cleans Tempfiles created throughout a request (i.e. Rack::Multipart)
9
+ # Ideas/strategy based on posts by Eric Wong and Charles Oliver Nutter
10
+ # https://groups.google.com/forum/#!searchin/rack-devel/temp/rack-devel/brK8eh-MByw/sw61oJJCGRMJ
11
+ class TempfileReaper
12
+ RESPONSE_FINISHED_HANDLER = proc { |env|
13
+ env[RACK_TEMPFILES]&.each(&:close!)
14
+ }
15
+ private_constant :RESPONSE_FINISHED_HANDLER
16
+
17
+ def initialize(app)
18
+ @app = app
19
+ end
20
+
21
+ def call(env)
22
+ env[RACK_TEMPFILES] ||= []
23
+
24
+ if response_finished = env[RACK_RESPONSE_FINISHED]
25
+ response_finished << RESPONSE_FINISHED_HANDLER
26
+
27
+ @app.call(env)
28
+ else
29
+ begin
30
+ _, _, body = response = @app.call(env)
31
+ rescue Exception
32
+ env[RACK_TEMPFILES]&.each(&:close!)
33
+ raise
34
+ end
35
+
36
+ response[2] = BodyProxy.new(body) do
37
+ env[RACK_TEMPFILES]&.each(&:close!)
38
+ end
39
+
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ require_relative 'constants'
6
+
7
+ module Rack
8
+ # Rack::URLMap takes a hash mapping urls or paths to apps, and
9
+ # dispatches accordingly. Support for HTTP/1.1 host names exists if
10
+ # the URLs start with <tt>http://</tt> or <tt>https://</tt>.
11
+ #
12
+ # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part
13
+ # relevant for dispatch is in the SCRIPT_NAME, and the rest in the
14
+ # PATH_INFO. This should be taken care of when you need to
15
+ # reconstruct the URL in order to create links.
16
+ #
17
+ # URLMap dispatches in such a way that the longest paths are tried
18
+ # first, since they are most specific.
19
+
20
+ class URLMap
21
+ def initialize(map = {})
22
+ remap(map)
23
+ end
24
+
25
+ def remap(map)
26
+ @known_hosts = Set[]
27
+ @mapping = map.map { |location, app|
28
+ if location =~ %r{\Ahttps?://(.*?)(/.*)}
29
+ host, location = $1, $2
30
+ @known_hosts << host
31
+ else
32
+ host = nil
33
+ end
34
+
35
+ unless location[0] == ?/
36
+ raise ArgumentError, "paths need to start with /"
37
+ end
38
+
39
+ location = location.chomp('/')
40
+ match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)", Regexp::NOENCODING).freeze
41
+
42
+ [host, location, match, app]
43
+ }.sort_by do |(host, location, _, _)|
44
+ [host ? -host.size : Float::INFINITY, -location.size]
45
+ end
46
+ end
47
+
48
+ def call(env)
49
+ path = env[PATH_INFO]
50
+ script_name = env[SCRIPT_NAME]
51
+ http_host = env[HTTP_HOST]
52
+ server_name = env[SERVER_NAME]
53
+ server_port = env[SERVER_PORT]
54
+
55
+ is_same_server = casecmp?(http_host, server_name) ||
56
+ casecmp?(http_host, "#{server_name}:#{server_port}")
57
+
58
+ is_host_known = @known_hosts.include? http_host
59
+
60
+ @mapping.each do |host, location, match, app|
61
+ unless casecmp?(http_host, host) \
62
+ || casecmp?(server_name, host) \
63
+ || (!host && is_same_server) \
64
+ || (!host && !is_host_known) # If we don't have a matching host, default to the first without a specified host
65
+ next
66
+ end
67
+
68
+ next unless m = match.match(path.to_s)
69
+
70
+ rest = m[1]
71
+ next unless !rest || rest.empty? || rest[0] == ?/
72
+
73
+ env[SCRIPT_NAME] = (script_name + location)
74
+ env[PATH_INFO] = rest
75
+
76
+ return app.call(env)
77
+ end
78
+
79
+ [404, { CONTENT_TYPE => "text/plain", "x-cascade" => "pass" }, ["Not Found: #{path}"]]
80
+
81
+ ensure
82
+ env[PATH_INFO] = path
83
+ env[SCRIPT_NAME] = script_name
84
+ end
85
+
86
+ private
87
+ def casecmp?(v1, v2)
88
+ # if both nil, or they're the same string
89
+ return true if v1 == v2
90
+
91
+ # if either are nil... (but they're not the same)
92
+ return false if v1.nil?
93
+ return false if v2.nil?
94
+
95
+ # otherwise check they're not case-insensitive the same
96
+ v1.casecmp(v2).zero?
97
+ end
98
+ end
99
+ end