Class: SHL::Request

Inherits:
Object
  • Object
show all
Includes:
AttributeInitializer
Defined in:
lib/shl/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeInitializer

#initialize

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/shl/request.rb', line 3

def body
  @body
end

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/shl/request.rb', line 3

def headers
  @headers
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/shl/request.rb', line 3

def url
  @url
end

#verbObject

Returns the value of attribute verb.



3
4
5
# File 'lib/shl/request.rb', line 3

def verb
  @verb
end

Instance Method Details

#connectionObject



15
16
17
# File 'lib/shl/request.rb', line 15

def connection
  @connection ||= TCPSocket.new(@url.host, @url.port)
end

#pathObject



11
12
13
# File 'lib/shl/request.rb', line 11

def path
  @url.path == '' ? '/' : @url.path
end

#request_lineObject



19
20
21
# File 'lib/shl/request.rb', line 19

def request_line
  "#{verb.to_s.upcase} #{path} #{HTTP_VERSION}"
end

#runObject



40
41
42
43
44
# File 'lib/shl/request.rb', line 40

def run
  connection.write([request_line,serialized_headers,serialized_body].join(NEWLINE))
  connection.flush
  Response.new(:io=>connection)
end

#serialized_bodyObject



36
37
38
# File 'lib/shl/request.rb', line 36

def serialized_body
  @body.to_s + NEWLINE
end

#serialized_headersObject



30
31
32
33
34
# File 'lib/shl/request.rb', line 30

def serialized_headers
  headers.map do |key, value|
    "#{key}: #{value}"
  end.join(NEWLINE)
end