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,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mock_request'
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'stringio'
5
+
6
+ require_relative 'constants'
7
+ require_relative 'mock_response'
8
+
9
+ module Rack
10
+ # Rack::MockRequest helps testing your Rack application without
11
+ # actually using HTTP.
12
+ #
13
+ # After performing a request on a URL with get/post/put/patch/delete, it
14
+ # returns a MockResponse with useful helper methods for effective
15
+ # testing.
16
+ #
17
+ # You can pass a hash with additional configuration to the
18
+ # get/post/put/patch/delete.
19
+ # <tt>:input</tt>:: A String or IO-like to be used as rack.input.
20
+ # <tt>:fatal</tt>:: Raise a FatalWarning if the app writes to rack.errors.
21
+ # <tt>:lint</tt>:: If true, wrap the application in a Rack::Lint.
22
+
23
+ class MockRequest
24
+ class FatalWarning < RuntimeError
25
+ end
26
+
27
+ class FatalWarner
28
+ def puts(warning)
29
+ raise FatalWarning, warning
30
+ end
31
+
32
+ def write(warning)
33
+ raise FatalWarning, warning
34
+ end
35
+
36
+ def flush
37
+ end
38
+
39
+ def string
40
+ ""
41
+ end
42
+ end
43
+
44
+ def initialize(app)
45
+ @app = app
46
+ end
47
+
48
+ # Make a GET request and return a MockResponse. See #request.
49
+ def get(uri, opts = {}) request(GET, uri, opts) end
50
+ # Make a POST request and return a MockResponse. See #request.
51
+ def post(uri, opts = {}) request(POST, uri, opts) end
52
+ # Make a PUT request and return a MockResponse. See #request.
53
+ def put(uri, opts = {}) request(PUT, uri, opts) end
54
+ # Make a PATCH request and return a MockResponse. See #request.
55
+ def patch(uri, opts = {}) request(PATCH, uri, opts) end
56
+ # Make a DELETE request and return a MockResponse. See #request.
57
+ def delete(uri, opts = {}) request(DELETE, uri, opts) end
58
+ # Make a HEAD request and return a MockResponse. See #request.
59
+ def head(uri, opts = {}) request(HEAD, uri, opts) end
60
+ # Make an OPTIONS request and return a MockResponse. See #request.
61
+ def options(uri, opts = {}) request(OPTIONS, uri, opts) end
62
+
63
+ # Make a request using the given request method for the given
64
+ # uri to the rack application and return a MockResponse.
65
+ # Options given are passed to MockRequest.env_for.
66
+ def request(method = GET, uri = "", opts = {})
67
+ env = self.class.env_for(uri, opts.merge(method: method))
68
+
69
+ if opts[:lint]
70
+ app = Rack::Lint.new(@app)
71
+ else
72
+ app = @app
73
+ end
74
+
75
+ errors = env[RACK_ERRORS]
76
+ status, headers, body = app.call(env)
77
+ MockResponse.new(status, headers, body, errors)
78
+ ensure
79
+ body.close if body.respond_to?(:close)
80
+ end
81
+
82
+ # For historical reasons, we're pinning to RFC 2396.
83
+ # URI::Parser = URI::RFC2396_Parser
84
+ def self.parse_uri_rfc2396(uri)
85
+ @parser ||= URI::Parser.new
86
+ @parser.parse(uri)
87
+ end
88
+
89
+ # Return the Rack environment used for a request to +uri+.
90
+ # All options that are strings are added to the returned environment.
91
+ # Options:
92
+ # :fatal :: Whether to raise an exception if request outputs to rack.errors
93
+ # :input :: The rack.input to set
94
+ # :http_version :: The SERVER_PROTOCOL to set
95
+ # :method :: The HTTP request method to use
96
+ # :params :: The params to use
97
+ # :script_name :: The SCRIPT_NAME to set
98
+ def self.env_for(uri = "", opts = {})
99
+ uri = parse_uri_rfc2396(uri)
100
+ uri.path = "/#{uri.path}" unless uri.path[0] == ?/
101
+
102
+ env = {}
103
+
104
+ env[REQUEST_METHOD] = (opts[:method] ? opts[:method].to_s.upcase : GET).b
105
+ env[SERVER_NAME] = (uri.host || "example.org").b
106
+ env[SERVER_PORT] = (uri.port ? uri.port.to_s : "80").b
107
+ env[SERVER_PROTOCOL] = opts[:http_version] || 'HTTP/1.1'
108
+ env[QUERY_STRING] = (uri.query.to_s).b
109
+ env[PATH_INFO] = (uri.path).b
110
+ env[RACK_URL_SCHEME] = (uri.scheme || "http").b
111
+ env[HTTPS] = (env[RACK_URL_SCHEME] == "https" ? "on" : "off").b
112
+
113
+ env[SCRIPT_NAME] = opts[:script_name] || ""
114
+
115
+ if opts[:fatal]
116
+ env[RACK_ERRORS] = FatalWarner.new
117
+ else
118
+ env[RACK_ERRORS] = StringIO.new
119
+ end
120
+
121
+ if params = opts[:params]
122
+ if env[REQUEST_METHOD] == GET
123
+ params = Utils.parse_nested_query(params) if params.is_a?(String)
124
+ params.update(Utils.parse_nested_query(env[QUERY_STRING]))
125
+ env[QUERY_STRING] = Utils.build_nested_query(params)
126
+ elsif !opts.has_key?(:input)
127
+ opts["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
128
+ if params.is_a?(Hash)
129
+ if data = Rack::Multipart.build_multipart(params)
130
+ opts[:input] = data
131
+ opts["CONTENT_LENGTH"] ||= data.length.to_s
132
+ opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Rack::Multipart::MULTIPART_BOUNDARY}"
133
+ else
134
+ opts[:input] = Utils.build_nested_query(params)
135
+ end
136
+ else
137
+ opts[:input] = params
138
+ end
139
+ end
140
+ end
141
+
142
+ rack_input = opts[:input]
143
+ if String === rack_input
144
+ rack_input = StringIO.new(rack_input)
145
+ end
146
+
147
+ if rack_input
148
+ rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
149
+ env[RACK_INPUT] = rack_input
150
+
151
+ env["CONTENT_LENGTH"] ||= env[RACK_INPUT].size.to_s if env[RACK_INPUT].respond_to?(:size)
152
+ end
153
+
154
+ opts.each { |field, value|
155
+ env[field] = value if String === field
156
+ }
157
+
158
+ env
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+ require 'time'
5
+
6
+ require_relative 'response'
7
+
8
+ module Rack
9
+ # Rack::MockResponse provides useful helpers for testing your apps.
10
+ # Usually, you don't create the MockResponse on your own, but use
11
+ # MockRequest.
12
+
13
+ class MockResponse < Rack::Response
14
+ class Cookie
15
+ attr_reader :name, :value, :path, :domain, :expires, :secure
16
+
17
+ def initialize(args)
18
+ @name = args["name"]
19
+ @value = args["value"]
20
+ @path = args["path"]
21
+ @domain = args["domain"]
22
+ @expires = args["expires"]
23
+ @secure = args["secure"]
24
+ end
25
+
26
+ def method_missing(method_name, *args, &block)
27
+ @value.send(method_name, *args, &block)
28
+ end
29
+ # :nocov:
30
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
31
+ # :nocov:
32
+
33
+ def respond_to_missing?(method_name, include_all = false)
34
+ @value.respond_to?(method_name, include_all) || super
35
+ end
36
+ end
37
+
38
+ class << self
39
+ alias [] new
40
+ end
41
+
42
+ # Headers
43
+ attr_reader :original_headers, :cookies
44
+
45
+ # Errors
46
+ attr_accessor :errors
47
+
48
+ def initialize(status, headers, body, errors = nil)
49
+ @original_headers = headers
50
+
51
+ if errors
52
+ @errors = errors.string if errors.respond_to?(:string)
53
+ else
54
+ @errors = ""
55
+ end
56
+
57
+ super(body, status, headers)
58
+
59
+ @cookies = parse_cookies_from_header
60
+ buffered_body!
61
+ end
62
+
63
+ def =~(other)
64
+ body =~ other
65
+ end
66
+
67
+ def match(other)
68
+ body.match other
69
+ end
70
+
71
+ def body
72
+ return @buffered_body if defined?(@buffered_body)
73
+
74
+ # FIXME: apparently users of MockResponse expect the return value of
75
+ # MockResponse#body to be a string. However, the real response object
76
+ # returns the body as a list.
77
+ #
78
+ # See spec_showstatus.rb:
79
+ #
80
+ # should "not replace existing messages" do
81
+ # ...
82
+ # res.body.should == "foo!"
83
+ # end
84
+ buffer = @buffered_body = String.new
85
+
86
+ begin
87
+ if @body.respond_to?(:each)
88
+ @body.each do |chunk|
89
+ buffer << chunk
90
+ end
91
+ else
92
+ @body.call(StringIO.new(buffer))
93
+ end
94
+ ensure
95
+ @body.close if @body.respond_to?(:close)
96
+ end
97
+
98
+ return buffer
99
+ end
100
+
101
+ def empty?
102
+ [201, 204, 304].include? status
103
+ end
104
+
105
+ def cookie(name)
106
+ cookies.fetch(name, nil)
107
+ end
108
+
109
+ private
110
+
111
+ def parse_cookies_from_header
112
+ cookies = Hash.new
113
+ set_cookie_header = headers['set-cookie']
114
+ if set_cookie_header && !set_cookie_header.empty?
115
+ Array(set_cookie_header).each do |cookie|
116
+ cookie_name, cookie_filling = cookie.split('=', 2)
117
+ cookie_attributes = identify_cookie_attributes cookie_filling
118
+ parsed_cookie = Cookie.new(
119
+ 'name' => cookie_name.strip,
120
+ 'value' => cookie_attributes.fetch('value'),
121
+ 'path' => cookie_attributes.fetch('path', nil),
122
+ 'domain' => cookie_attributes.fetch('domain', nil),
123
+ 'expires' => cookie_attributes.fetch('expires', nil),
124
+ 'secure' => cookie_attributes.fetch('secure', false)
125
+ )
126
+ cookies.store(cookie_name, parsed_cookie)
127
+ end
128
+ end
129
+ cookies
130
+ end
131
+
132
+ def identify_cookie_attributes(cookie_filling)
133
+ cookie_bits = cookie_filling.split(';')
134
+ cookie_attributes = Hash.new
135
+ cookie_attributes.store('value', Array(cookie_bits[0].strip))
136
+ cookie_bits.drop(1).each do |bit|
137
+ if bit.include? '='
138
+ cookie_attribute, attribute_value = bit.split('=', 2)
139
+ cookie_attributes.store(cookie_attribute.strip.downcase, attribute_value.strip)
140
+ end
141
+ if bit.include? 'secure'
142
+ cookie_attributes.store('secure', true)
143
+ end
144
+ end
145
+
146
+ if cookie_attributes.key? 'max-age'
147
+ cookie_attributes.store('expires', Time.now + cookie_attributes['max-age'].to_i)
148
+ elsif cookie_attributes.key? 'expires'
149
+ cookie_attributes.store('expires', Time.httpdate(cookie_attributes['expires']))
150
+ end
151
+
152
+ cookie_attributes
153
+ end
154
+
155
+ end
156
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'uploaded_file'
4
+
5
+ module Rack
6
+ module Multipart
7
+ class Generator
8
+ def initialize(params, first = true)
9
+ @params, @first = params, first
10
+
11
+ if @first && !@params.is_a?(Hash)
12
+ raise ArgumentError, "value must be a Hash"
13
+ end
14
+ end
15
+
16
+ def dump
17
+ return nil if @first && !multipart?
18
+ return flattened_params unless @first
19
+
20
+ flattened_params.map do |name, file|
21
+ if file.respond_to?(:original_filename)
22
+ if file.path
23
+ ::File.open(file.path, 'rb') do |f|
24
+ f.set_encoding(Encoding::BINARY)
25
+ content_for_tempfile(f, file, name)
26
+ end
27
+ else
28
+ content_for_tempfile(file, file, name)
29
+ end
30
+ else
31
+ content_for_other(file, name)
32
+ end
33
+ end.join << "--#{MULTIPART_BOUNDARY}--\r"
34
+ end
35
+
36
+ private
37
+ def multipart?
38
+ query = lambda { |value|
39
+ case value
40
+ when Array
41
+ value.any?(&query)
42
+ when Hash
43
+ value.values.any?(&query)
44
+ when Rack::Multipart::UploadedFile
45
+ true
46
+ end
47
+ }
48
+
49
+ @params.values.any?(&query)
50
+ end
51
+
52
+ def flattened_params
53
+ @flattened_params ||= begin
54
+ h = Hash.new
55
+ @params.each do |key, value|
56
+ k = @first ? key.to_s : "[#{key}]"
57
+
58
+ case value
59
+ when Array
60
+ value.map { |v|
61
+ Multipart.build_multipart(v, false).each { |subkey, subvalue|
62
+ h["#{k}[]#{subkey}"] = subvalue
63
+ }
64
+ }
65
+ when Hash
66
+ Multipart.build_multipart(value, false).each { |subkey, subvalue|
67
+ h[k + subkey] = subvalue
68
+ }
69
+ else
70
+ h[k] = value
71
+ end
72
+ end
73
+ h
74
+ end
75
+ end
76
+
77
+ def content_for_tempfile(io, file, name)
78
+ length = ::File.stat(file.path).size if file.path
79
+ filename = "; filename=\"#{Utils.escape_path(file.original_filename)}\""
80
+ <<-EOF
81
+ --#{MULTIPART_BOUNDARY}\r
82
+ content-disposition: form-data; name="#{name}"#{filename}\r
83
+ content-type: #{file.content_type}\r
84
+ #{"content-length: #{length}\r\n" if length}\r
85
+ #{io.read}\r
86
+ EOF
87
+ end
88
+
89
+ def content_for_other(file, name)
90
+ <<-EOF
91
+ --#{MULTIPART_BOUNDARY}\r
92
+ content-disposition: form-data; name="#{name}"\r
93
+ \r
94
+ #{file}\r
95
+ EOF
96
+ end
97
+ end
98
+ end
99
+ end