Class: Gopher::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gopher2000/request.rb

Overview

basic class for an incoming request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, ip_addr = nil) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
15
# File 'lib/gopher2000/request.rb', line 9

def initialize(raw, ip_addr=nil)
  @raw = raw
  @selector, @input = @raw.chomp.split("\t")
  
 @selector = Gopher::Application.sanitize_selector(@selector)
 @ip_address = ip_addr
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



7
8
9
# File 'lib/gopher2000/request.rb', line 7

def input
  @input
end

#ip_addressObject

Returns the value of attribute ip_address.



7
8
9
# File 'lib/gopher2000/request.rb', line 7

def ip_address
  @ip_address
end

#selectorObject

Returns the value of attribute selector.



7
8
9
# File 'lib/gopher2000/request.rb', line 7

def selector
  @selector
end

Instance Method Details

#urlObject



21
22
23
# File 'lib/gopher2000/request.rb', line 21

def url
  @raw.chomp.split("\t").first.gsub(/^URL\:/, '')
end

#url?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/gopher2000/request.rb', line 17

def url?
  @raw =~ /^URL\:/
end

#valid?Boolean

confirm that this is actually a valid gopher request

Returns:

  • (Boolean)

    true if the request is valid, false otherwise



27
28
29
30
# File 'lib/gopher2000/request.rb', line 27

def valid?
  # The Selector string should be no longer than 255 characters. (RFC 1436)
  @selector.length <= 255
end