I read that HTTParty uses SSL if the port is set to 443, but I don't see how to set the port. Can someone clarify this for me?
Asked
Active
Viewed 6,287 times
2 Answers
5
Check the specs:
The target URL is expected to use port 443. Just adding the :443
at the end of the target URI should be enough to make HTTParty use SSL.
By the way, HTTPS URLs will use SSL too.
Examples:
http://foo.com => no SSL
https://foo.com => SSL
http://foo.com:443 => SSL

the Tin Man
- 158,662
- 42
- 215
- 303

Roberto Decurnex
- 2,514
- 1
- 19
- 28
-
1+1. Best to specify `https://` in the URL, as the port will default to 443 automatically. – Mark Thomas Oct 29 '12 at 16:15
-
Agreed with @MarkThomas . Good to know that you can use both anyway. – Roberto Decurnex Oct 29 '12 at 16:28
3
It actually uses HTTPS by default unless the port is 80 and the request is HTTP:
context "using port 80" do
let(:uri) { URI 'http://foobar.com' }
it { should_not use_ssl }
end
context "using port 443 for ssl" do
let(:uri) { URI 'https://api.foo.com/v1:443' }
it { should use_ssl }
end
context "https scheme with default port" do
it { should use_ssl }
end
context "https scheme with non-standard port" do
let(:uri) { URI 'https://foobar.com:123456' }
it { should use_ssl }
end
https://github.com/jnunemaker/httparty/blob/master/spec/httparty/connection_adapter_spec.rb
Here's my spec:
describe Foo do
it 'is https' do
adapter = HTTParty::ConnectionAdapter.new(URI(subject.base_uri))
expect(adapter.connection.use_ssl?).to eq(true)
end
end

Rimian
- 36,864
- 16
- 117
- 117