sealights-rspec-agent 2.0.4 → 2.0.5
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.
- checksums.yaml +4 -4
- data/agent/config.rb +6 -6
- data/agent/dependencies/faraday-0.17.0/LICENSE.md +20 -0
- data/agent/dependencies/faraday-0.17.0/README.md +384 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday.rb +248 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter.rb +55 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_http.rb +243 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_synchrony.rb +106 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_synchrony/parallel_manager.rb +66 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/excon.rb +82 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/httpclient.rb +128 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/net_http.rb +152 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/net_http_persistent.rb +68 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/patron.rb +95 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/rack.rb +58 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/sl_em_http_ssl_patch.rb +56 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/test.rb +213 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/typhoeus.rb +12 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/autoload.rb +84 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/connection.rb +484 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/error.rb +66 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/middleware.rb +37 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/options.rb +373 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/parameters.rb +198 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/rack_builder.rb +237 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request.rb +114 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/authorization.rb +41 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/basic_authentication.rb +13 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/instrumentation.rb +36 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/multipart.rb +68 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/retry.rb +212 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/token_authentication.rb +15 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/url_encoded.rb +36 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response.rb +97 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response/logger.rb +80 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response/raise_error.rb +21 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/upload_io.rb +67 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/utils.rb +326 -0
- data/agent/dependencies/jwt-2.2.1/AUTHORS +84 -0
- data/agent/dependencies/jwt-2.2.1/Appraisals +14 -0
- data/agent/dependencies/jwt-2.2.1/CHANGELOG.md +570 -0
- data/agent/dependencies/jwt-2.2.1/Gemfile +3 -0
- data/agent/dependencies/jwt-2.2.1/LICENSE +7 -0
- data/agent/dependencies/jwt-2.2.1/README.md +489 -0
- data/agent/dependencies/jwt-2.2.1/Rakefile +11 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt.rb +30 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/ecdsa.rb +35 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/eddsa.rb +23 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/hmac.rb +33 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/ps.rb +43 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/rsa.rb +19 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/unsupported.rb +16 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/base64.rb +19 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/claims_validator.rb +33 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/decode.rb +100 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/default_options.rb +15 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/encode.rb +68 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/error.rb +20 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/json.rb +18 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk.rb +31 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk/key_finder.rb +57 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk/rsa.rb +47 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/security_utils.rb +57 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/signature.rb +52 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/verify.rb +98 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/version.rb +24 -0
- data/agent/dependencies/jwt-2.2.1/ruby-jwt.gemspec +34 -0
- data/agent/dependencies/multipart-post-2.1.1/Gemfile +6 -0
- data/agent/dependencies/multipart-post-2.1.1/History.txt +64 -0
- data/agent/dependencies/multipart-post-2.1.1/LICENSE +21 -0
- data/agent/dependencies/multipart-post-2.1.1/Manifest.txt +9 -0
- data/agent/dependencies/multipart-post-2.1.1/README.md +127 -0
- data/agent/dependencies/multipart-post-2.1.1/Rakefile +6 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/composite_io.rb +108 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/multipart_post.rb +9 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/multipartable.rb +48 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/net/http/post/multipart.rb +28 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/parts.rb +126 -0
- data/agent/dependencies/multipart-post-2.1.1/multipart-post.gemspec +23 -0
- data/agent/http_client.rb +46 -0
- data/agent/listener.rb +1 -1
- data/agent/sealights-rspec-agent.rb +2 -2
- data/agent/tia.rb +5 -1
- metadata +80 -3
- data/agent/rest-client-wrapper.rb +0 -27
@@ -0,0 +1,64 @@
|
|
1
|
+
<!--
|
2
|
+
# @markup rdoc
|
3
|
+
# @title CHANGELOG
|
4
|
+
-->
|
5
|
+
|
6
|
+
=== 2.0.0 / 2013-12-21
|
7
|
+
|
8
|
+
- Drop Ruby 1.8 compatibility
|
9
|
+
- GH #21: Fix FilePart length calculation for Ruby 1.9 when filename contains
|
10
|
+
multibyte characters (hexfet)
|
11
|
+
- GH #20: Ensure upload responds to both #content_type and #original_filename
|
12
|
+
(Steven Davidovitz)
|
13
|
+
- GH #31: Support setting headers on any part of the request (Socrates Vicente)
|
14
|
+
- GH #30: Support array values for params (Gustav Ernberg)
|
15
|
+
- GH #32: Fix respond_to? signature (Leo Cassarani)
|
16
|
+
- GH #33: Update README to markdown (Jagtesh Chadha)
|
17
|
+
- GH #35: Improved handling of array-type parameters (Steffen Grunwald)
|
18
|
+
|
19
|
+
=== 1.2.0 / 2013-02-25
|
20
|
+
|
21
|
+
- #25: Ruby 2 compatibility (thanks mislav)
|
22
|
+
|
23
|
+
=== 1.1.5 / 2012-02-12
|
24
|
+
|
25
|
+
- Fix length/bytesize of parts in 1.9 (#7, #14) (Jason Moore)
|
26
|
+
- Allow CompositeIO objects to be re-read by rewinding, like other IO
|
27
|
+
objects. (Luke Redpath)
|
28
|
+
|
29
|
+
=== 1.1.4 / 2011-11-23
|
30
|
+
|
31
|
+
- Non-functional changes in release (switch to Bundler gem tasks)
|
32
|
+
|
33
|
+
=== 1.1.3 / 2011-07-25
|
34
|
+
|
35
|
+
- More configurable header specification for parts (Gerrit Riessen)
|
36
|
+
|
37
|
+
=== 1.1.2 / 2011-05-24
|
38
|
+
|
39
|
+
- Fix CRLF file part miscalculation (Johannes Wagener)
|
40
|
+
- Fix Epilogue CRLF issue (suggestion by Neil Spring)
|
41
|
+
|
42
|
+
=== 1.1.1 / 2011-05-13
|
43
|
+
|
44
|
+
- GH# 9: Fixed Ruby 1.9.2 StringIO bug (thanks Alex Koppel)
|
45
|
+
|
46
|
+
=== 1.1.0 / 2011-01-11
|
47
|
+
|
48
|
+
- API CHANGE: UploadIO.convert! removed in favor of UploadIO.new
|
49
|
+
(Jeff Hodges)
|
50
|
+
|
51
|
+
=== 1.0.1 / 2010-04-27
|
52
|
+
|
53
|
+
- Doc updates, make gemspec based on more modern Rubygems
|
54
|
+
|
55
|
+
=== 1.0 / 2009-02-12
|
56
|
+
|
57
|
+
- Many fixes from mlooney, seems to work now. Putting the 0.9 seal of
|
58
|
+
approval on it.
|
59
|
+
|
60
|
+
=== 0.1 / 2008-08-12
|
61
|
+
|
62
|
+
* 1 major enhancement
|
63
|
+
|
64
|
+
* Birthday!
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2007-2013 Nick Sieger nick@nicksieger.com
|
2
|
+
Copyright, 2017, by Samuel G. D. Williams.
|
3
|
+
|
4
|
+
MIT license.
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
8
|
+
the Software without restriction, including without limitation the rights to
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
10
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
11
|
+
subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
18
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
19
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Multipart::Post
|
2
|
+
|
3
|
+
Adds a streamy multipart form post capability to `Net::HTTP`. Also supports other
|
4
|
+
methods besides `POST`.
|
5
|
+
|
6
|
+
[](http://travis-ci.org/socketry/multipart-post)
|
7
|
+
|
8
|
+
## Features/Problems
|
9
|
+
|
10
|
+
* Appears to actually work. A good feature to have.
|
11
|
+
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
12
|
+
most browsers' file upload forms.
|
13
|
+
* Provides an `UploadIO` helper class to prepare IO objects for inclusion in the params
|
14
|
+
hash of the multipart post object.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
gem install multipart-post
|
19
|
+
|
20
|
+
or in your Gemfile
|
21
|
+
|
22
|
+
gem 'multipart-post'
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'net/http/post/multipart'
|
28
|
+
|
29
|
+
url = URI.parse('http://www.example.com/upload')
|
30
|
+
File.open("./image.jpg") do |jpg|
|
31
|
+
req = Net::HTTP::Post::Multipart.new url.path,
|
32
|
+
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
33
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
34
|
+
http.request(req)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
To post multiple files or attachments, simply include multiple parameters with
|
40
|
+
`UploadIO` values:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'net/http/post/multipart'
|
44
|
+
|
45
|
+
url = URI.parse('http://www.example.com/upload')
|
46
|
+
req = Net::HTTP::Post::Multipart.new url.path,
|
47
|
+
"file1" => UploadIO.new(File.new("./image.jpg"), "image/jpeg", "image.jpg"),
|
48
|
+
"file2" => UploadIO.new(File.new("./image2.jpg"), "image/jpeg", "image2.jpg")
|
49
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
50
|
+
http.request(req)
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
To post files with other normal, non-file params such as input values, you need to pass hashes to the `Multipart.new` method.
|
55
|
+
|
56
|
+
In Rails 4 for example:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
def model_params
|
60
|
+
require_params = params.require(:model).permit(:param_one, :param_two, :param_three, :avatar)
|
61
|
+
require_params[:avatar] = model_params[:avatar].present? ? UploadIO.new(model_params[:avatar].tempfile, model_params[:avatar].content_type, model_params[:avatar].original_filename) : nil
|
62
|
+
require_params
|
63
|
+
end
|
64
|
+
|
65
|
+
require 'net/http/post/multipart'
|
66
|
+
|
67
|
+
url = URI.parse('http://www.example.com/upload')
|
68
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
69
|
+
req = Net::HTTP::Post::Multipart.new(url, model_params)
|
70
|
+
key = "authorization_key"
|
71
|
+
req.add_field("Authorization", key) #add to Headers
|
72
|
+
http.use_ssl = (url.scheme == "https")
|
73
|
+
http.request(req)
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Or in plain ruby:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
def params(file)
|
81
|
+
params = { "description" => "A nice picture!" }
|
82
|
+
params[:datei] = UploadIO.new(file, "image/jpeg", "image.jpg")
|
83
|
+
params
|
84
|
+
end
|
85
|
+
|
86
|
+
url = URI.parse('http://www.example.com/upload')
|
87
|
+
File.open("./image.jpg") do |file|
|
88
|
+
req = Net::HTTP::Post::Multipart.new(url.path, params(file))
|
89
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
90
|
+
return http.request(req).body
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
### Debugging
|
96
|
+
|
97
|
+
You can debug requests and responses (e.g. status codes) for all requests by adding the following code:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
101
|
+
http.set_debug_output($stdout)
|
102
|
+
```
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
Released under the MIT license.
|
107
|
+
|
108
|
+
Copyright (c) 2007-2013 Nick Sieger <nick@nicksieger.com>
|
109
|
+
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
110
|
+
|
111
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
112
|
+
of this software and associated documentation files (the "Software"), to deal
|
113
|
+
in the Software without restriction, including without limitation the rights
|
114
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
115
|
+
copies of the Software, and to permit persons to whom the Software is
|
116
|
+
furnished to do so, subject to the following conditions:
|
117
|
+
|
118
|
+
The above copyright notice and this permission notice shall be included in
|
119
|
+
all copies or substantial portions of the Software.
|
120
|
+
|
121
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
122
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
123
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
124
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
125
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
126
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
127
|
+
THE SOFTWARE.
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2012 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
# Concatenate together multiple IO objects into a single, composite IO object
|
8
|
+
# for purposes of reading as a single stream.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# crio = CompositeReadIO.new(StringIO.new('one'),
|
12
|
+
# StringIO.new('two'),
|
13
|
+
# StringIO.new('three'))
|
14
|
+
# puts crio.read # => "onetwothree"
|
15
|
+
class SLCompositeReadIO
|
16
|
+
# Create a new composite-read IO from the arguments, all of which should
|
17
|
+
# respond to #read in a manner consistent with IO.
|
18
|
+
def initialize(*ios)
|
19
|
+
@ios = ios.flatten
|
20
|
+
@index = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
# Read from IOs in order until `length` bytes have been received.
|
24
|
+
def read(length = nil, outbuf = nil)
|
25
|
+
got_result = false
|
26
|
+
outbuf = outbuf ? outbuf.replace("") : ""
|
27
|
+
|
28
|
+
while io = current_io
|
29
|
+
if result = io.read(length)
|
30
|
+
got_result ||= !result.nil?
|
31
|
+
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
32
|
+
outbuf << result
|
33
|
+
length -= result.length if length
|
34
|
+
break if length == 0
|
35
|
+
end
|
36
|
+
advance_io
|
37
|
+
end
|
38
|
+
(!got_result && length) ? nil : outbuf
|
39
|
+
end
|
40
|
+
|
41
|
+
def rewind
|
42
|
+
@ios.each { |io| io.rewind }
|
43
|
+
@index = 0
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def current_io
|
49
|
+
@ios[@index]
|
50
|
+
end
|
51
|
+
|
52
|
+
def advance_io
|
53
|
+
@index += 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Convenience methods for dealing with files and IO that are to be uploaded.
|
58
|
+
class SLUploadIO
|
59
|
+
attr_reader :content_type, :original_filename, :local_path, :io, :opts
|
60
|
+
|
61
|
+
# Create an upload IO suitable for including in the params hash of a
|
62
|
+
# Net::HTTP::Post::Multipart.
|
63
|
+
#
|
64
|
+
# Can take two forms. The first accepts a filename and content type, and
|
65
|
+
# opens the file for reading (to be closed by finalizer).
|
66
|
+
#
|
67
|
+
# The second accepts an already-open IO, but also requires a third argument,
|
68
|
+
# the filename from which it was opened (particularly useful/recommended if
|
69
|
+
# uploading directly from a form in a framework, which often save the file to
|
70
|
+
# an arbitrarily named RackMultipart file in /tmp).
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# UploadIO.new("file.txt", "text/plain")
|
74
|
+
# UploadIO.new(file_io, "text/plain", "file.txt")
|
75
|
+
def initialize(filename_or_io, content_type, filename = nil, opts = {})
|
76
|
+
io = filename_or_io
|
77
|
+
local_path = ""
|
78
|
+
if io.respond_to? :read
|
79
|
+
# in Ruby 1.9.2, StringIOs no longer respond to path
|
80
|
+
# (since they respond to :length, so we don't need their local path, see parts.rb:41)
|
81
|
+
local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : "local.path"
|
82
|
+
else
|
83
|
+
io = File.open(filename_or_io)
|
84
|
+
local_path = filename_or_io
|
85
|
+
end
|
86
|
+
filename ||= local_path
|
87
|
+
|
88
|
+
@content_type = content_type
|
89
|
+
@original_filename = File.basename(filename)
|
90
|
+
@local_path = local_path
|
91
|
+
@io = io
|
92
|
+
@opts = opts
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.convert!(io, content_type, original_filename, local_path)
|
96
|
+
raise ArgumentError, "convert! has been removed. You must now wrap IOs " \
|
97
|
+
"using:\nUploadIO.new(filename_or_io, content_type, " \
|
98
|
+
"filename=nil)\nPlease update your code."
|
99
|
+
end
|
100
|
+
|
101
|
+
def method_missing(*args)
|
102
|
+
@io.send(*args)
|
103
|
+
end
|
104
|
+
|
105
|
+
def respond_to?(meth, include_all = false)
|
106
|
+
@io.respond_to?(meth, include_all) || super(meth, include_all)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2013 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
require_relative 'parts'
|
8
|
+
require 'securerandom'
|
9
|
+
|
10
|
+
module SLMultipartable
|
11
|
+
def self.secure_boundary
|
12
|
+
# https://tools.ietf.org/html/rfc7230
|
13
|
+
# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
|
14
|
+
# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
|
15
|
+
# / DIGIT / ALPHA
|
16
|
+
|
17
|
+
# https://tools.ietf.org/html/rfc2046
|
18
|
+
# bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
|
19
|
+
# "+" / "_" / "," / "-" / "." /
|
20
|
+
# "/" / ":" / "=" / "?"
|
21
|
+
|
22
|
+
"--#{SecureRandom.uuid}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(path, params, headers={}, boundary = SLMultipartable.secure_boundary)
|
26
|
+
headers = headers.clone # don't want to modify the original variable
|
27
|
+
parts_headers = headers.delete(:parts) || {}
|
28
|
+
super(path, headers)
|
29
|
+
parts = params.map do |k,v|
|
30
|
+
case v
|
31
|
+
when Array
|
32
|
+
v.map {|item| SLParts::Part.new(boundary, k, item, parts_headers[k]) }
|
33
|
+
else
|
34
|
+
SLParts::Part.new(boundary, k, v, parts_headers[k])
|
35
|
+
end
|
36
|
+
end.flatten
|
37
|
+
parts << SLParts::EpiloguePart.new(boundary)
|
38
|
+
ios = parts.map {|p| p.to_io }
|
39
|
+
self.set_content_type(headers["Content-Type"] || "multipart/form-data",
|
40
|
+
{ "boundary" => boundary })
|
41
|
+
self.content_length = parts.inject(0) {|sum,i| sum + i.length }
|
42
|
+
self.body_stream = SLCompositeReadIO.new(*ios)
|
43
|
+
|
44
|
+
@boundary = boundary
|
45
|
+
end
|
46
|
+
|
47
|
+
attr :boundary
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2012 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
require 'stringio'
|
9
|
+
require 'cgi'
|
10
|
+
require_relative '../../../composite_io'
|
11
|
+
require_relative '../../../multipartable'
|
12
|
+
require_relative '../../../parts'
|
13
|
+
|
14
|
+
module Net
|
15
|
+
class HTTP
|
16
|
+
class Put
|
17
|
+
class Multipart < Put
|
18
|
+
include SLMultipartable
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Post
|
23
|
+
class Multipart < Post
|
24
|
+
include SLMultipartable
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2013 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
module SLParts
|
8
|
+
module Part
|
9
|
+
def self.new(boundary, name, value, headers = {})
|
10
|
+
headers ||= {} # avoid nil values
|
11
|
+
if file?(value)
|
12
|
+
FilePart.new(boundary, name, value, headers)
|
13
|
+
else
|
14
|
+
ParamPart.new(boundary, name, value, headers)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.file?(value)
|
19
|
+
value.respond_to?(:content_type) && value.respond_to?(:original_filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
def length
|
23
|
+
@part.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_io
|
27
|
+
@io
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Represents a parametric part to be filled with given value.
|
32
|
+
class ParamPart
|
33
|
+
include Part
|
34
|
+
|
35
|
+
# @param boundary [String]
|
36
|
+
# @param name [#to_s]
|
37
|
+
# @param value [String]
|
38
|
+
# @param headers [Hash] Content-Type is used, if present.
|
39
|
+
def initialize(boundary, name, value, headers = {})
|
40
|
+
@part = build_part(boundary, name, value, headers)
|
41
|
+
@io = StringIO.new(@part)
|
42
|
+
end
|
43
|
+
|
44
|
+
def length
|
45
|
+
@part.bytesize
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param boundary [String]
|
49
|
+
# @param name [#to_s]
|
50
|
+
# @param value [String]
|
51
|
+
# @param headers [Hash] Content-Type is used, if present.
|
52
|
+
def build_part(boundary, name, value, headers = {})
|
53
|
+
part = ''
|
54
|
+
part << "--#{boundary}\r\n"
|
55
|
+
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
|
56
|
+
part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
|
57
|
+
part << "\r\n"
|
58
|
+
part << "#{value}\r\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Represents a part to be filled from file IO.
|
63
|
+
class FilePart
|
64
|
+
include Part
|
65
|
+
|
66
|
+
attr_reader :length
|
67
|
+
|
68
|
+
# @param boundary [String]
|
69
|
+
# @param name [#to_s]
|
70
|
+
# @param io [IO]
|
71
|
+
# @param headers [Hash]
|
72
|
+
def initialize(boundary, name, io, headers = {})
|
73
|
+
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
74
|
+
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
|
75
|
+
io.respond_to?(:opts) ? io.opts.merge(headers) : headers)
|
76
|
+
@foot = "\r\n"
|
77
|
+
@length = @head.bytesize + file_length + @foot.length
|
78
|
+
@io = SLCompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param boundary [String]
|
82
|
+
# @param name [#to_s]
|
83
|
+
# @param filename [String]
|
84
|
+
# @param type [String]
|
85
|
+
# @param content_len [Integer]
|
86
|
+
# @param opts [Hash]
|
87
|
+
def build_head(boundary, name, filename, type, content_len, opts = {})
|
88
|
+
opts = opts.clone
|
89
|
+
|
90
|
+
trans_encoding = opts.delete("Content-Transfer-Encoding") || "binary"
|
91
|
+
content_disposition = opts.delete("Content-Disposition") || "form-data"
|
92
|
+
|
93
|
+
part = ''
|
94
|
+
part << "--#{boundary}\r\n"
|
95
|
+
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
96
|
+
part << "Content-Length: #{content_len}\r\n"
|
97
|
+
if content_id = opts.delete("Content-ID")
|
98
|
+
part << "Content-ID: #{content_id}\r\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
if opts["Content-Type"] != nil
|
102
|
+
part << "Content-Type: " + opts["Content-Type"] + "\r\n"
|
103
|
+
else
|
104
|
+
part << "Content-Type: #{type}\r\n"
|
105
|
+
end
|
106
|
+
|
107
|
+
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
|
108
|
+
|
109
|
+
opts.each do |k, v|
|
110
|
+
part << "#{k}: #{v}\r\n"
|
111
|
+
end
|
112
|
+
|
113
|
+
part << "\r\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Represents the epilogue or closing boundary.
|
118
|
+
class EpiloguePart
|
119
|
+
include Part
|
120
|
+
|
121
|
+
def initialize(boundary)
|
122
|
+
@part = "--#{boundary}--\r\n"
|
123
|
+
@io = StringIO.new(@part)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|