Skip to content

Commit

Permalink
Merge pull request #66 from takezoe/follow-redirect-option
Browse files Browse the repository at this point in the history
Add follow_redirect option
  • Loading branch information
takezoe authored Mar 18, 2021
2 parents c8c3251 + 64c0b81 commit 9f1b297
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ client = Presto::Client.new(
},
http_proxy: "proxy.example.com:8080",
http_debug: true,
follow_redirect: true
)

# run a query and get results as an array of arrays:
Expand Down
4 changes: 3 additions & 1 deletion lib/presto/client/faraday_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def self.faraday_client(options)
if options[:user] && options[:password]
faraday.basic_auth(options[:user], options[:password])
end

if options[:follow_redirect]
faraday.use FaradayMiddleware::FollowRedirects
end
faraday.response :logger if options[:http_debug]
faraday.adapter Faraday.default_adapter
end
Expand Down
1 change: 1 addition & 0 deletions lib/presto/client/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
module Presto::Client

require 'faraday'
require 'faraday_middleware'
require 'presto/client/models'
require 'presto/client/errors'
require 'presto/client/faraday_client'
Expand Down
1 change: 1 addition & 0 deletions presto-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = ">= 1.9.1"

gem.add_dependency "faraday", ["~> 0.12"]
gem.add_dependency "faraday_middleware", ["~> 0.12.2"]
gem.add_dependency "msgpack", [">= 0.7.0"]

gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"]
Expand Down
14 changes: 14 additions & 0 deletions spec/statement_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
time_zone: "US/Pacific",
language: "ja_JP",
debug: true,
follow_redirect: true
}
end

Expand Down Expand Up @@ -229,6 +230,19 @@
statement_client.query_info
end.should raise_error(PrestoHttpError, /Presto API returned unexpected data format./)
end

it "is redirected if server returned 301" do
stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
with(headers: headers).
to_return(status: 301, headers: {"Location" => "http://localhost/v1/query/redirected"})

stub_request(:get, "http://localhost/v1/query/redirected").
with(headers: headers).
to_return(body: {"queryId" => "queryid"}.to_json)

query_info = statement_client.query_info
query_info.query_id.should == "queryid"
end
end

describe "Killing a query" do
Expand Down

0 comments on commit 9f1b297

Please sign in to comment.