nano-sharp-hub 0.0.1

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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/nano-sharp-hub.gemspec +12 -0
  3. data/rack-3.2.6/CHANGELOG.md +1346 -0
  4. data/rack-3.2.6/CONTRIBUTING.md +144 -0
  5. data/rack-3.2.6/MIT-LICENSE +20 -0
  6. data/rack-3.2.6/README.md +384 -0
  7. data/rack-3.2.6/SPEC.rdoc +258 -0
  8. data/rack-3.2.6/lib/rack/auth/abstract/handler.rb +41 -0
  9. data/rack-3.2.6/lib/rack/auth/abstract/request.rb +51 -0
  10. data/rack-3.2.6/lib/rack/auth/basic.rb +58 -0
  11. data/rack-3.2.6/lib/rack/bad_request.rb +8 -0
  12. data/rack-3.2.6/lib/rack/body_proxy.rb +63 -0
  13. data/rack-3.2.6/lib/rack/builder.rb +296 -0
  14. data/rack-3.2.6/lib/rack/cascade.rb +67 -0
  15. data/rack-3.2.6/lib/rack/common_logger.rb +89 -0
  16. data/rack-3.2.6/lib/rack/conditional_get.rb +87 -0
  17. data/rack-3.2.6/lib/rack/config.rb +22 -0
  18. data/rack-3.2.6/lib/rack/constants.rb +68 -0
  19. data/rack-3.2.6/lib/rack/content_length.rb +34 -0
  20. data/rack-3.2.6/lib/rack/content_type.rb +33 -0
  21. data/rack-3.2.6/lib/rack/deflater.rb +158 -0
  22. data/rack-3.2.6/lib/rack/directory.rb +208 -0
  23. data/rack-3.2.6/lib/rack/etag.rb +71 -0
  24. data/rack-3.2.6/lib/rack/events.rb +172 -0
  25. data/rack-3.2.6/lib/rack/files.rb +216 -0
  26. data/rack-3.2.6/lib/rack/head.rb +25 -0
  27. data/rack-3.2.6/lib/rack/headers.rb +238 -0
  28. data/rack-3.2.6/lib/rack/lint.rb +964 -0
  29. data/rack-3.2.6/lib/rack/lock.rb +29 -0
  30. data/rack-3.2.6/lib/rack/media_type.rb +52 -0
  31. data/rack-3.2.6/lib/rack/method_override.rb +56 -0
  32. data/rack-3.2.6/lib/rack/mime.rb +694 -0
  33. data/rack-3.2.6/lib/rack/mock.rb +3 -0
  34. data/rack-3.2.6/lib/rack/mock_request.rb +161 -0
  35. data/rack-3.2.6/lib/rack/mock_response.rb +156 -0
  36. data/rack-3.2.6/lib/rack/multipart/generator.rb +99 -0
  37. data/rack-3.2.6/lib/rack/multipart/parser.rb +621 -0
  38. data/rack-3.2.6/lib/rack/multipart/uploaded_file.rb +82 -0
  39. data/rack-3.2.6/lib/rack/multipart.rb +77 -0
  40. data/rack-3.2.6/lib/rack/null_logger.rb +48 -0
  41. data/rack-3.2.6/lib/rack/query_parser.rb +261 -0
  42. data/rack-3.2.6/lib/rack/recursive.rb +66 -0
  43. data/rack-3.2.6/lib/rack/reloader.rb +112 -0
  44. data/rack-3.2.6/lib/rack/request.rb +790 -0
  45. data/rack-3.2.6/lib/rack/response.rb +403 -0
  46. data/rack-3.2.6/lib/rack/rewindable_input.rb +116 -0
  47. data/rack-3.2.6/lib/rack/runtime.rb +35 -0
  48. data/rack-3.2.6/lib/rack/sendfile.rb +197 -0
  49. data/rack-3.2.6/lib/rack/show_exceptions.rb +409 -0
  50. data/rack-3.2.6/lib/rack/show_status.rb +121 -0
  51. data/rack-3.2.6/lib/rack/static.rb +192 -0
  52. data/rack-3.2.6/lib/rack/tempfile_reaper.rb +33 -0
  53. data/rack-3.2.6/lib/rack/urlmap.rb +99 -0
  54. data/rack-3.2.6/lib/rack/utils.rb +714 -0
  55. data/rack-3.2.6/lib/rack/version.rb +17 -0
  56. data/rack-3.2.6/lib/rack.rb +64 -0
  57. metadata +96 -0
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ require_relative 'constants'
6
+ require_relative 'utils'
7
+ require_relative 'request'
8
+ require_relative 'body_proxy'
9
+
10
+ module Rack
11
+ # Rack::ShowStatus catches all empty responses and replaces them
12
+ # with a site explaining the error.
13
+ #
14
+ # Additional details can be put into <tt>rack.showstatus.detail</tt>
15
+ # and will be shown as HTML. If such details exist, the error page
16
+ # is always rendered, even if the reply was not empty.
17
+
18
+ class ShowStatus
19
+ def initialize(app)
20
+ @app = app
21
+ @template = ERB.new(TEMPLATE)
22
+ end
23
+
24
+ def call(env)
25
+ status, headers, body = response = @app.call(env)
26
+ empty = headers[CONTENT_LENGTH].to_i <= 0
27
+
28
+ # client or server error, or explicit message
29
+ if (status.to_i >= 400 && empty) || env[RACK_SHOWSTATUS_DETAIL]
30
+ # This double assignment is to prevent an "unused variable" warning.
31
+ # Yes, it is dumb, but I don't like Ruby yelling at me.
32
+ req = req = Rack::Request.new(env)
33
+
34
+ message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
35
+
36
+ # This double assignment is to prevent an "unused variable" warning.
37
+ # Yes, it is dumb, but I don't like Ruby yelling at me.
38
+ detail = detail = env[RACK_SHOWSTATUS_DETAIL] || message
39
+
40
+ html = @template.result(binding)
41
+ size = html.bytesize
42
+
43
+ response[2] = Rack::BodyProxy.new([html]) do
44
+ body.close if body.respond_to?(:close)
45
+ end
46
+
47
+ headers[CONTENT_TYPE] = "text/html"
48
+ headers[CONTENT_LENGTH] = size.to_s
49
+ end
50
+
51
+ response
52
+ end
53
+
54
+ def h(obj) # :nodoc:
55
+ case obj
56
+ when String
57
+ Utils.escape_html(obj)
58
+ else
59
+ Utils.escape_html(obj.inspect)
60
+ end
61
+ end
62
+
63
+ # :stopdoc:
64
+
65
+ # adapted from Django <www.djangoproject.com>
66
+ # Copyright (c) Django Software Foundation and individual contributors.
67
+ # Used under the modified BSD license:
68
+ # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
69
+ TEMPLATE = <<'HTML'
70
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
71
+ <html lang="en">
72
+ <head>
73
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
74
+ <title><%=h message %> at <%=h req.script_name + req.path_info %></title>
75
+ <meta name="robots" content="NONE,NOARCHIVE" />
76
+ <style type="text/css">
77
+ html * { padding:0; margin:0; }
78
+ body * { padding:10px 20px; }
79
+ body * * { padding:0; }
80
+ body { font:small sans-serif; background:#eee; }
81
+ body>div { border-bottom:1px solid #ddd; }
82
+ h1 { font-weight:normal; margin-bottom:.4em; }
83
+ h1 span { font-size:60%; color:#666; font-weight:normal; }
84
+ table { border:none; border-collapse: collapse; width:100%; }
85
+ td, th { vertical-align:top; padding:2px 3px; }
86
+ th { width:12em; text-align:right; color:#666; padding-right:.5em; }
87
+ #info { background:#f6f6f6; }
88
+ #info ol { margin: 0.5em 4em; }
89
+ #info ol li { font-family: monospace; }
90
+ #summary { background: #ffc; }
91
+ #explanation { background:#eee; border-bottom: 0px none; }
92
+ </style>
93
+ </head>
94
+ <body>
95
+ <div id="summary">
96
+ <h1><%=h message %> <span>(<%= status.to_i %>)</span></h1>
97
+ <table class="meta">
98
+ <tr>
99
+ <th>Request Method:</th>
100
+ <td><%=h req.request_method %></td>
101
+ </tr>
102
+ <tr>
103
+ <th>Request URL:</th>
104
+ <td><%=h req.url %></td>
105
+ </tr>
106
+ </table>
107
+ </div>
108
+ <div id="info">
109
+ <p><%=h detail %></p>
110
+ </div>
111
+
112
+ <div id="explanation">
113
+ <p>
114
+ You're seeing this error because you use <code>Rack::ShowStatus</code>.
115
+ </p>
116
+ </div>
117
+ </body>
118
+ </html>
119
+ HTML
120
+ end
121
+ end
@@ -0,0 +1,192 @@
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
+ if @urls.kind_of?(Array)
97
+ @urls = @urls.map { |url| [url, url.end_with?('/') ? url : "#{url}/".freeze].freeze }.freeze
98
+ end
99
+ @index = options[:index]
100
+ @gzip = options[:gzip]
101
+ @cascade = options[:cascade]
102
+ root = options[:root] || Dir.pwd
103
+
104
+ # HTTP Headers
105
+ @header_rules = options[:header_rules] || []
106
+ # Allow for legacy :cache_control option while prioritizing global header_rules setting
107
+ @header_rules.unshift([:all, { CACHE_CONTROL => options[:cache_control] }]) if options[:cache_control]
108
+
109
+ @file_server = Rack::Files.new(root)
110
+ end
111
+
112
+ def add_index_root?(path)
113
+ @index && route_file(path) && path.end_with?('/')
114
+ end
115
+
116
+ def overwrite_file_path(path)
117
+ @urls.kind_of?(Hash) && @urls.key?(path) || add_index_root?(path)
118
+ end
119
+
120
+ def route_file(path)
121
+ @urls.kind_of?(Array) && @urls.any? { |url, url_slash| path == url || path.start_with?(url_slash) }
122
+ end
123
+
124
+ def can_serve(path)
125
+ route_file(path) || overwrite_file_path(path)
126
+ end
127
+
128
+ def call(env)
129
+ path = env[PATH_INFO]
130
+ actual_path = Utils.clean_path_info(Utils.unescape_path(path))
131
+
132
+ if can_serve(actual_path)
133
+ if overwrite_file_path(path)
134
+ env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
135
+ elsif @gzip && env['HTTP_ACCEPT_ENCODING'] && /\bgzip\b/.match?(env['HTTP_ACCEPT_ENCODING'])
136
+ path = env[PATH_INFO]
137
+ env[PATH_INFO] += '.gz'
138
+ response = @file_server.call(env)
139
+ env[PATH_INFO] = path
140
+
141
+ if response[0] == 404
142
+ response = nil
143
+ elsif response[0] == 304
144
+ # Do nothing, leave headers as is
145
+ else
146
+ response[1][CONTENT_TYPE] = Mime.mime_type(::File.extname(path), 'text/plain')
147
+ response[1]['content-encoding'] = 'gzip'
148
+ end
149
+ end
150
+
151
+ path = env[PATH_INFO]
152
+ response ||= @file_server.call(env)
153
+
154
+ if @cascade && response[0] == 404
155
+ return @app.call(env)
156
+ end
157
+
158
+ headers = response[1]
159
+ applicable_rules(path).each do |rule, new_headers|
160
+ new_headers.each { |field, content| headers[field] = content }
161
+ end
162
+
163
+ response
164
+ else
165
+ @app.call(env)
166
+ end
167
+ end
168
+
169
+ # Convert HTTP header rules to HTTP headers
170
+ def applicable_rules(path)
171
+ path = ::Rack::Utils.unescape_path(path)
172
+
173
+ @header_rules.find_all do |rule, new_headers|
174
+ case rule
175
+ when :all
176
+ true
177
+ when :fonts
178
+ /\.(?:ttf|otf|eot|woff2|woff|svg)\z/.match?(path)
179
+ when String
180
+ path.start_with?(rule) || path.start_with?('/' + rule)
181
+ when Array
182
+ /\.#{Regexp.union(rule)}\z/.match?(path)
183
+ when Regexp
184
+ rule.match?(path)
185
+ else
186
+ false
187
+ end
188
+ end
189
+ end
190
+
191
+ end
192
+ end
@@ -0,0 +1,33 @@
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
+ def initialize(app)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ env[RACK_TEMPFILES] ||= []
18
+
19
+ begin
20
+ _, _, body = response = @app.call(env)
21
+ rescue Exception
22
+ env[RACK_TEMPFILES]&.each(&:close!)
23
+ raise
24
+ end
25
+
26
+ response[2] = BodyProxy.new(body) do
27
+ env[RACK_TEMPFILES]&.each(&:close!)
28
+ end
29
+
30
+ response
31
+ end
32
+ end
33
+ 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)
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