Class: UDPRest::UHTTPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/udp_rest/uhttp.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUHTTPRequest

Returns a new instance of UHTTPRequest.



11
12
13
14
15
# File 'lib/udp_rest/uhttp.rb', line 11

def initialize
    self.req_method = 'GET'
    self.protocol = 'UHTTP/1.0'
    self.path ='/'
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/udp_rest/uhttp.rb', line 8

def path
  @path
end

#protocolObject

Returns the value of attribute protocol.



9
10
11
# File 'lib/udp_rest/uhttp.rb', line 9

def protocol
  @protocol
end

#req_methodObject

Returns the value of attribute req_method.



7
8
9
# File 'lib/udp_rest/uhttp.rb', line 7

def req_method
  @req_method
end

Class Method Details

.from_packet(p) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/udp_rest/uhttp.rb', line 17

def self.from_packet(p)
    text = p
    text = p.text if text.is_a? UDPPacket
    data = text.split(' ')

    raise 'invalid request' if data.length != 3
    req = self.new
    req.req_method = data[0]
    req.path = data[1]
    req.protocol = data[2]
    return req
end

Instance Method Details

#to_sObject



30
31
32
33
# File 'lib/udp_rest/uhttp.rb', line 30

def to_s
    self.path = '/' if path.nil? || path.empty?
    "#{req_method} #{path} #{protocol}\n"
end