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,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ require_relative 'constants'
6
+ require_relative 'head'
7
+ require_relative 'utils'
8
+ require_relative 'request'
9
+ require_relative 'mime'
10
+
11
+ module Rack
12
+ # Rack::Files serves files below the +root+ directory given, according to the
13
+ # path info of the Rack request.
14
+ # e.g. when Rack::Files.new("/etc") is used, you can access 'passwd' file
15
+ # as http://localhost:9292/passwd
16
+ #
17
+ # Handlers can detect if bodies are a Rack::Files, and use mechanisms
18
+ # like sendfile on the +path+.
19
+
20
+ class Files
21
+ ALLOWED_VERBS = %w[GET HEAD OPTIONS]
22
+ ALLOW_HEADER = ALLOWED_VERBS.join(', ')
23
+ MULTIPART_BOUNDARY = 'AaB03x'
24
+
25
+ attr_reader :root
26
+
27
+ def initialize(root, headers = {}, default_mime = 'text/plain')
28
+ @root = (::File.expand_path(root) if root)
29
+ @headers = headers
30
+ @default_mime = default_mime
31
+ @head = Rack::Head.new(lambda { |env| get env })
32
+ end
33
+
34
+ def call(env)
35
+ # HEAD requests drop the response body, including 4xx error messages.
36
+ @head.call env
37
+ end
38
+
39
+ def get(env)
40
+ request = Rack::Request.new env
41
+ unless ALLOWED_VERBS.include? request.request_method
42
+ return fail(405, "Method Not Allowed", { 'allow' => ALLOW_HEADER })
43
+ end
44
+
45
+ path_info = Utils.unescape_path request.path_info
46
+ return fail(400, "Bad Request") unless Utils.valid_path?(path_info)
47
+
48
+ clean_path_info = Utils.clean_path_info(path_info)
49
+ path = ::File.join(@root, clean_path_info)
50
+
51
+ available = begin
52
+ ::File.file?(path) && ::File.readable?(path)
53
+ rescue SystemCallError
54
+ # Not sure in what conditions this exception can occur, but this
55
+ # is a safe way to handle such an error.
56
+ # :nocov:
57
+ false
58
+ # :nocov:
59
+ end
60
+
61
+ if available
62
+ serving(request, path)
63
+ else
64
+ fail(404, "File not found: #{path_info}")
65
+ end
66
+ end
67
+
68
+ def serving(request, path)
69
+ if request.options?
70
+ return [200, { 'allow' => ALLOW_HEADER, CONTENT_LENGTH => '0' }, []]
71
+ end
72
+ last_modified = ::File.mtime(path).httpdate
73
+ return [304, {}, []] if request.get_header('HTTP_IF_MODIFIED_SINCE') == last_modified
74
+
75
+ headers = { "last-modified" => last_modified }
76
+ mime_type = mime_type path, @default_mime
77
+ headers[CONTENT_TYPE] = mime_type if mime_type
78
+
79
+ # Set custom headers
80
+ headers.merge!(@headers) if @headers
81
+
82
+ status = 200
83
+ size = filesize path
84
+
85
+ ranges = Rack::Utils.get_byte_ranges(request.get_header('HTTP_RANGE'), size)
86
+ if ranges.nil?
87
+ # No ranges:
88
+ ranges = [0..size - 1]
89
+ elsif ranges.empty?
90
+ # Unsatisfiable. Return error, and file size:
91
+ response = fail(416, "Byte range unsatisfiable")
92
+ response[1]["content-range"] = "bytes */#{size}"
93
+ return response
94
+ else
95
+ # Partial content
96
+ partial_content = true
97
+
98
+ if ranges.size == 1
99
+ range = ranges[0]
100
+ headers["content-range"] = "bytes #{range.begin}-#{range.end}/#{size}"
101
+ else
102
+ headers[CONTENT_TYPE] = "multipart/byteranges; boundary=#{MULTIPART_BOUNDARY}"
103
+ end
104
+
105
+ status = 206
106
+ body = BaseIterator.new(path, ranges, mime_type: mime_type, size: size)
107
+ size = body.bytesize
108
+ end
109
+
110
+ headers[CONTENT_LENGTH] = size.to_s
111
+
112
+ if request.head?
113
+ body = []
114
+ elsif !partial_content
115
+ body = Iterator.new(path, ranges, mime_type: mime_type, size: size)
116
+ end
117
+
118
+ [status, headers, body]
119
+ end
120
+
121
+ class BaseIterator
122
+ attr_reader :path, :ranges, :options
123
+
124
+ def initialize(path, ranges, options)
125
+ @path = path
126
+ @ranges = ranges
127
+ @options = options
128
+ end
129
+
130
+ def each
131
+ ::File.open(path, "rb") do |file|
132
+ ranges.each do |range|
133
+ yield multipart_heading(range) if multipart?
134
+
135
+ each_range_part(file, range) do |part|
136
+ yield part
137
+ end
138
+ end
139
+
140
+ yield "\r\n--#{MULTIPART_BOUNDARY}--\r\n" if multipart?
141
+ end
142
+ end
143
+
144
+ def bytesize
145
+ size = ranges.inject(0) do |sum, range|
146
+ sum += multipart_heading(range).bytesize if multipart?
147
+ sum += range.size
148
+ end
149
+ size += "\r\n--#{MULTIPART_BOUNDARY}--\r\n".bytesize if multipart?
150
+ size
151
+ end
152
+
153
+ def close; end
154
+
155
+ private
156
+
157
+ def multipart?
158
+ ranges.size > 1
159
+ end
160
+
161
+ def multipart_heading(range)
162
+ <<-EOF
163
+ \r
164
+ --#{MULTIPART_BOUNDARY}\r
165
+ content-type: #{options[:mime_type]}\r
166
+ content-range: bytes #{range.begin}-#{range.end}/#{options[:size]}\r
167
+ \r
168
+ EOF
169
+ end
170
+
171
+ def each_range_part(file, range)
172
+ file.seek(range.begin)
173
+ remaining_len = range.end - range.begin + 1
174
+ while remaining_len > 0
175
+ part = file.read([8192, remaining_len].min)
176
+ break unless part
177
+ remaining_len -= part.length
178
+
179
+ yield part
180
+ end
181
+ end
182
+ end
183
+
184
+ class Iterator < BaseIterator
185
+ alias :to_path :path
186
+ end
187
+
188
+ private
189
+
190
+ def fail(status, body, headers = {})
191
+ body += "\n"
192
+
193
+ [
194
+ status,
195
+ {
196
+ CONTENT_TYPE => "text/plain",
197
+ CONTENT_LENGTH => body.bytesize.to_s,
198
+ "x-cascade" => "pass"
199
+ }.merge!(headers),
200
+ [body]
201
+ ]
202
+ end
203
+
204
+ # The MIME type for the contents of the file located at @path
205
+ def mime_type(path, default_mime)
206
+ Mime.mime_type(::File.extname(path), default_mime)
207
+ end
208
+
209
+ def filesize(path)
210
+ # We check via File::size? whether this file provides size info
211
+ # via stat (e.g. /proc files often don't), otherwise we have to
212
+ # figure it out by reading the whole file into memory.
213
+ ::File.size?(path) || ::File.read(path).bytesize
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'body_proxy'
5
+
6
+ module Rack
7
+ # Rack::Head returns an empty body for all HEAD requests. It leaves
8
+ # all other requests unchanged.
9
+ class Head
10
+ def initialize(app)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ _, _, body = response = @app.call(env)
16
+
17
+ if env[REQUEST_METHOD] == HEAD
18
+ body.close if body.respond_to?(:close)
19
+ response[2] = []
20
+ end
21
+
22
+ response
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,238 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ # Rack::Headers is a Hash subclass that downcases all keys. It's designed
5
+ # to be used by rack applications that don't implement the Rack 3 SPEC
6
+ # (by using non-lowercase response header keys), automatically handling
7
+ # the downcasing of keys.
8
+ class Headers < Hash
9
+ KNOWN_HEADERS = {}
10
+ %w(
11
+ Accept-CH
12
+ Accept-Patch
13
+ Accept-Ranges
14
+ Access-Control-Allow-Credentials
15
+ Access-Control-Allow-Headers
16
+ Access-Control-Allow-Methods
17
+ Access-Control-Allow-Origin
18
+ Access-Control-Expose-Headers
19
+ Access-Control-Max-Age
20
+ Age
21
+ Allow
22
+ Alt-Svc
23
+ Cache-Control
24
+ Connection
25
+ Content-Disposition
26
+ Content-Encoding
27
+ Content-Language
28
+ Content-Length
29
+ Content-Location
30
+ Content-MD5
31
+ Content-Range
32
+ Content-Security-Policy
33
+ Content-Security-Policy-Report-Only
34
+ Content-Type
35
+ Date
36
+ Delta-Base
37
+ ETag
38
+ Expect-CT
39
+ Expires
40
+ Feature-Policy
41
+ IM
42
+ Last-Modified
43
+ Link
44
+ Location
45
+ NEL
46
+ P3P
47
+ Permissions-Policy
48
+ Pragma
49
+ Preference-Applied
50
+ Proxy-Authenticate
51
+ Public-Key-Pins
52
+ Referrer-Policy
53
+ Refresh
54
+ Report-To
55
+ Retry-After
56
+ Server
57
+ Set-Cookie
58
+ Status
59
+ Strict-Transport-Security
60
+ Timing-Allow-Origin
61
+ Tk
62
+ Trailer
63
+ Transfer-Encoding
64
+ Upgrade
65
+ Vary
66
+ Via
67
+ WWW-Authenticate
68
+ Warning
69
+ X-Cascade
70
+ X-Content-Duration
71
+ X-Content-Security-Policy
72
+ X-Content-Type-Options
73
+ X-Correlation-ID
74
+ X-Correlation-Id
75
+ X-Download-Options
76
+ X-Frame-Options
77
+ X-Permitted-Cross-Domain-Policies
78
+ X-Powered-By
79
+ X-Redirect-By
80
+ X-Request-ID
81
+ X-Request-Id
82
+ X-Runtime
83
+ X-UA-Compatible
84
+ X-WebKit-CS
85
+ X-XSS-Protection
86
+ ).each do |str|
87
+ downcased = str.downcase.freeze
88
+ KNOWN_HEADERS[str] = KNOWN_HEADERS[downcased] = downcased
89
+ end
90
+
91
+ def self.[](*items)
92
+ if items.length % 2 != 0
93
+ if items.length == 1 && items.first.is_a?(Hash)
94
+ new.merge!(items.first)
95
+ else
96
+ raise ArgumentError, "odd number of arguments for Rack::Headers"
97
+ end
98
+ else
99
+ hash = new
100
+ loop do
101
+ break if items.length == 0
102
+ key = items.shift
103
+ value = items.shift
104
+ hash[key] = value
105
+ end
106
+ hash
107
+ end
108
+ end
109
+
110
+ def [](key)
111
+ super(downcase_key(key))
112
+ end
113
+
114
+ def []=(key, value)
115
+ super(KNOWN_HEADERS[key] || key.downcase.freeze, value)
116
+ end
117
+ alias store []=
118
+
119
+ def assoc(key)
120
+ super(downcase_key(key))
121
+ end
122
+
123
+ def compare_by_identity
124
+ raise TypeError, "Rack::Headers cannot compare by identity, use regular Hash"
125
+ end
126
+
127
+ def delete(key)
128
+ super(downcase_key(key))
129
+ end
130
+
131
+ def dig(key, *a)
132
+ super(downcase_key(key), *a)
133
+ end
134
+
135
+ def fetch(key, *default, &block)
136
+ key = downcase_key(key)
137
+ super
138
+ end
139
+
140
+ def fetch_values(*a)
141
+ super(*a.map!{|key| downcase_key(key)})
142
+ end
143
+
144
+ def has_key?(key)
145
+ super(downcase_key(key))
146
+ end
147
+ alias include? has_key?
148
+ alias key? has_key?
149
+ alias member? has_key?
150
+
151
+ def invert
152
+ hash = self.class.new
153
+ each{|key, value| hash[value] = key}
154
+ hash
155
+ end
156
+
157
+ def merge(hash, &block)
158
+ dup.merge!(hash, &block)
159
+ end
160
+
161
+ def reject(&block)
162
+ hash = dup
163
+ hash.reject!(&block)
164
+ hash
165
+ end
166
+
167
+ def replace(hash)
168
+ clear
169
+ update(hash)
170
+ end
171
+
172
+ def select(&block)
173
+ hash = dup
174
+ hash.select!(&block)
175
+ hash
176
+ end
177
+
178
+ def to_proc
179
+ lambda{|x| self[x]}
180
+ end
181
+
182
+ def transform_values(&block)
183
+ dup.transform_values!(&block)
184
+ end
185
+
186
+ def update(hash, &block)
187
+ hash.each do |key, value|
188
+ self[key] = if block_given? && include?(key)
189
+ block.call(key, self[key], value)
190
+ else
191
+ value
192
+ end
193
+ end
194
+ self
195
+ end
196
+ alias merge! update
197
+
198
+ def values_at(*keys)
199
+ keys.map{|key| self[key]}
200
+ end
201
+
202
+ # :nocov:
203
+ if RUBY_VERSION >= '2.5'
204
+ # :nocov:
205
+ def slice(*a)
206
+ h = self.class.new
207
+ a.each{|k| h[k] = self[k] if has_key?(k)}
208
+ h
209
+ end
210
+
211
+ def transform_keys(&block)
212
+ dup.transform_keys!(&block)
213
+ end
214
+
215
+ def transform_keys!
216
+ hash = self.class.new
217
+ each do |k, v|
218
+ hash[yield k] = v
219
+ end
220
+ replace(hash)
221
+ end
222
+ end
223
+
224
+ # :nocov:
225
+ if RUBY_VERSION >= '3.0'
226
+ # :nocov:
227
+ def except(*a)
228
+ super(*a.map!{|key| downcase_key(key)})
229
+ end
230
+ end
231
+
232
+ private
233
+
234
+ def downcase_key(key)
235
+ key.is_a?(String) ? KNOWN_HEADERS[key] || key.downcase : key
236
+ end
237
+ end
238
+ end