Class: Net::Tofu::Request
- Inherits:
-
Object
- Object
- Net::Tofu::Request
- Defined in:
- lib/net/tofu/request.rb,
lib/net/tofu/error.rb
Overview
Stores a client request to a Gemini server.
Defined Under Namespace
Classes: InvalidSchemeError, InvalidURIError
Constant Summary collapse
- MAX_URI_BYTESIZE =
1024
Instance Attribute Summary collapse
-
#fragment ⇒ String
readonly
A fragment to request from the host.
-
#host ⇒ String
readonly
The hostname of the request.
-
#path ⇒ String
readonly
The requested path on the host.
-
#port ⇒ Integer
readonly
The server port to connect on.
-
#queries ⇒ Array
readonly
Additional queries to send to the host.
-
#resp ⇒ Response
readonly
The response from the server after calling ##gets.
-
#scheme ⇒ String
readonly
The request scheme (i.e. gemini://, http://).
-
#uri ⇒ URI
readonly
The full URI object of the request.
Instance Method Summary collapse
-
#format ⇒ String
Format the URI for sending over a socket to a Gemini server.
-
#gets ⇒ Object
Connect to the server and try to fetch data.
-
#initialize(host, port: nil, trust: false) ⇒ Request
constructor
Constructor for the request type.
Constructor Details
#initialize(host, port: nil, trust: false) ⇒ Request
Constructor for the request type.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/net/tofu/request.rb', line 36 def initialize(host, port: nil, trust: false) @uri = URI(host) @uri.port = port unless port.nil? parse_head parse_tail # Make sure the URI isn't too large if format.bytesize > MAX_URI_BYTESIZE raise InvalidURIError, "The URI is too large, should be #{MAX_URI_BYTESIZE} bytes, instead is #{format.bytesize} bytes" end # Create a socket @sock = Socket.new(@host, @port, trust) end |
Instance Attribute Details
#fragment ⇒ String (readonly)
Returns A fragment to request from the host.
28 29 30 |
# File 'lib/net/tofu/request.rb', line 28 def fragment @fragment end |
#host ⇒ String (readonly)
Returns The hostname of the request.
16 17 18 |
# File 'lib/net/tofu/request.rb', line 16 def host @host end |
#path ⇒ String (readonly)
Returns The requested path on the host.
22 23 24 |
# File 'lib/net/tofu/request.rb', line 22 def path @path end |
#port ⇒ Integer (readonly)
Returns The server port to connect on.
19 20 21 |
# File 'lib/net/tofu/request.rb', line 19 def port @port end |
#queries ⇒ Array (readonly)
Returns Additional queries to send to the host.
25 26 27 |
# File 'lib/net/tofu/request.rb', line 25 def queries @queries end |
#resp ⇒ Response (readonly)
Returns The response from the server after calling ##gets.
31 32 33 |
# File 'lib/net/tofu/request.rb', line 31 def resp @resp end |
#scheme ⇒ String (readonly)
Returns The request scheme (i.e. gemini://, http://).
13 14 15 |
# File 'lib/net/tofu/request.rb', line 13 def scheme @scheme end |
#uri ⇒ URI (readonly)
Returns The full URI object of the request.
10 11 12 |
# File 'lib/net/tofu/request.rb', line 10 def uri @uri end |
Instance Method Details
#format ⇒ String
Format the URI for sending over a socket to a Gemini server.
55 56 57 |
# File 'lib/net/tofu/request.rb', line 55 def format "#{@uri}\r\n" end |
#gets ⇒ Object
Connect to the server and try to fetch data.
60 61 62 63 64 65 |
# File 'lib/net/tofu/request.rb', line 60 def gets @sock.connect @resp = @sock.gets(self) ensure @sock.close end |