Class: Net::GeminiRequest
- Inherits:
-
Object
- Object
- Net::GeminiRequest
- Defined in:
- lib/net/gemini/request.rb
Overview
The syntax of Gemini Requests are defined in the Gemini specification, section 2.
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uri_or_str) ⇒ GeminiRequest
constructor
A new instance of GeminiRequest.
- #path ⇒ Object
- #write(sock) ⇒ Object
Constructor Details
#initialize(uri_or_str) ⇒ GeminiRequest
Returns a new instance of GeminiRequest.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/net/gemini/request.rb', line 19 def initialize(uri_or_str) # In any case, make some sanity check over this uri-like think url = uri_or_str.to_s if url.length > 1024 raise GeminiBadRequest, "Request too long: #{url.dump}" end @uri = URI(url) unless uri.is_a? URI::Gemini raise GeminiBadRequest, "Not a Gemini URI: #{url.dump}" end end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
17 18 19 |
# File 'lib/net/gemini/request.rb', line 17 def uri @uri end |
Class Method Details
.read_new(sock) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/net/gemini/request.rb', line 40 def read_new(sock) # Read up to 1026 bytes: # - 1024 bytes max for the URL # - 2 bytes for <CR><LF> str = sock.gets($INPUT_RECORD_SEPARATOR, 1026) m = /\A(.*)\r\n\z/.match(str) raise GeminiBadRequest, "Malformed request: #{str.dump}" if m.nil? new(m[1]) end |
Instance Method Details
#path ⇒ Object
31 32 33 |
# File 'lib/net/gemini/request.rb', line 31 def path @uri.path end |
#write(sock) ⇒ Object
35 36 37 |
# File 'lib/net/gemini/request.rb', line 35 def write(sock) sock.puts "#{@uri}\r\n" end |