Skip to content

Commit 6f5e66d

Browse files
authored
Merge pull request #50 from QuickPay/overwrite-authorization-header
Overwrite authorization header
2 parents 1ac0c1c + 722e5b2 commit 6f5e66d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 4.0.2
4+
5+
Make overwritten Authorization header possible again.
6+
7+
## 4.0.1
8+
9+
Fix so that settings port number is no longer ignored
10+
11+
## 4.0.0
12+
13+
Replace Excon with std lib Net::HTTP, so raised errors will have different underlying errors.
14+
The returned header keys are all lowercase.
15+
316
## 3.0.1
417

518
* Fixed bug where variations of Content-Type application/json got scrubbed, fx application/json;charset=UTF-8 (https://github.com/QuickPay/quickpay-ruby-client/pull/41)

lib/quickpay/api/client.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def initialize(username: nil, password: nil, base_uri: "https://api.quickpay.net
6262
if (query = req.query) && query.any?
6363
uri.query = URI.encode_www_form(req.query)
6464
end
65-
net_req = method_class.new(uri, req.headers)
65+
net_req = method_class.new(uri)
6666
net_req.basic_auth(@username, @password) if @username || @password
67+
req.headers.each { |key, value| net_req[key] = value }
6768
net_req.body = req.body
6869
res = Net::HTTP.start(
6970
uri.hostname,

lib/quickpay/api/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module QuickPay
22
module API
3-
VERSION = "4.0.1".freeze
3+
VERSION = "4.0.2".freeze
44
end
55
end

test/client.rb

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
_(headers["authorization"]).must_equal "Basic OnNlY3JldA=="
3030
end
3131

32+
it "overwrites Authorization header if already set" do
33+
stub_request(:get, "http://localhost:4242/ping").to_return { |request| { headers: request.headers, status: 200 } }
34+
35+
client = QuickPay::API::Client.new(password: "secret", base_uri: "http://localhost:4242")
36+
_, _, headers = *client.get("/ping", headers: { Authorization: "Basic OnRlc3RfdXNlcg==" })
37+
38+
_(headers["accept-version"]).must_equal "v10"
39+
_(headers["user-agent"]).must_equal "quickpay-ruby-client, v#{QuickPay::API::VERSION}"
40+
_(headers["authorization"]).must_equal "Basic OnRlc3RfdXNlcg=="
41+
end
42+
3243
describe "JSON <=> Hash conversion of body" do
3344
subject { QuickPay::API::Client.new }
3445

0 commit comments

Comments
 (0)