Class: Net::Gemini::Client
- Inherits:
-
Object
- Object
- Net::Gemini::Client
- Defined in:
- lib/net/gemini/client.rb,
lib/net/gemini/client/ssl.rb
Overview
Reopen Client class to add specific private method to handle SSL connection
Instance Attribute Summary collapse
-
#certs_path ⇒ Object
writeonly
Sets the attribute certs_path.
Instance Method Summary collapse
- #fetch(uri, limit = 5) ⇒ Object
-
#initialize(host, port) ⇒ Client
constructor
A new instance of Client.
- #request(uri) ⇒ Object
-
#request!(uri) ⇒ Object
This method can raise an OpenSSL::SSL::SSLError.
Constructor Details
#initialize(host, port) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 |
# File 'lib/net/gemini/client.rb', line 14 def initialize(host, port) @host = host @port = port @certs_path = '~/.cache/gemini/certs' end |
Instance Attribute Details
#certs_path=(value) ⇒ Object (writeonly)
Sets the attribute certs_path
12 13 14 |
# File 'lib/net/gemini/client.rb', line 12 def certs_path=(value) @certs_path = value end |
Instance Method Details
#fetch(uri, limit = 5) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/net/gemini/client.rb', line 44 def fetch(uri, limit = 5) raise Error, 'Too many Gemini redirects' if limit.zero? r = request(uri) return r unless r.status[0] == '3' begin uri = handle_redirect(r) rescue ArgumentError, URI::InvalidURIError return r end warn "Redirect to #{uri}" if $VERBOSE fetch(uri, limit - 1) end |
#request(uri) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net/gemini/client.rb', line 30 def request(uri) request! uri rescue OpenSSL::SSL::SSLError => e msg = format( 'SSLError: %<cause>s', cause: e..sub(/.*state=error: (.+)\Z/, '\1') ) Response.new('59', msg) ensure # Stop remaining connection, even if they should be already cut # by the server finish end |