-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module HTTPI | ||
module Adapter | ||
class NetHTTPMultipart < NetHTTP | ||
|
||
register :net_http_multipart, :deps => %w(net/http/post/multipart) | ||
|
||
private | ||
|
||
def request_client(type) | ||
if [:post, :put].include?(type) | ||
request_class = Object.const_get("Net::HTTP::#{type.to_s.capitalize}::Multipart") | ||
|
||
request_client = request_class.new @request.url.request_uri, @request.attachments, @request.headers | ||
|
||
# set request body_stream | ||
@request.body_stream = request_client.body_stream | ||
|
||
request_client.basic_auth(*@request.auth.credentials) if @request.auth.basic? | ||
|
||
if @request.auth.digest? | ||
raise NotSupportedError, "Net::HTTP does not support HTTP digest authentication" | ||
end | ||
|
||
request_client | ||
else | ||
super(type) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require "spec_helper" | ||
require "integration/support/server" | ||
|
||
require "composite_io" | ||
|
||
describe HTTPI::Adapter::NetHTTPMultipart do | ||
|
||
subject(:adapter) { :net_http_multipart } | ||
|
||
describe "Net::HTTP with multipart data" do | ||
before :all do | ||
@server = IntegrationServer.run | ||
end | ||
|
||
after :all do | ||
@server.stop | ||
end | ||
|
||
it "executes POST requests with attachments" do | ||
# create some IO | ||
buffer = StringIO.new('hello world') | ||
|
||
# create attachments hash | ||
attachments = { "file" => UploadIO.new(buffer, 'text/plain') } | ||
|
||
# create request with attachments | ||
request = HTTPI::Request.new(url: @server.url + "/attachments", attachments: attachments) | ||
|
||
# perform request | ||
response = HTTPI.post(request, adapter) | ||
|
||
# run tests | ||
expect(response.body).to eq("files: #{attachments.keys.join(',')}") | ||
expect(response.headers["Content-Type"]).to eq("text/plain") | ||
end | ||
|
||
it "executes PUT requests with attachments" do | ||
# create some IO | ||
buffer = StringIO.new('hello world') | ||
|
||
# create attachments hash | ||
attachments = { "file" => UploadIO.new(buffer, 'text/plain') } | ||
|
||
# create request with attachments | ||
request = HTTPI::Request.new(url: @server.url + "/attachments", attachments: attachments) | ||
|
||
# perform request | ||
response = HTTPI.put(request, adapter) | ||
|
||
# run tests | ||
expect(response.body).to eq("files: #{attachments.keys.join(',')}") | ||
expect(response.headers["Content-Type"]).to eq("text/plain") | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters