Permalink
Browse files

Use readable variable names and spacing the request source file.

  • Loading branch information...
1 parent f869b22 commit 0c7b88e62e5ff3118f0fdbdee685a7337aee5477 @Manfred committed Apr 18, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/shl/request.rb
View
@@ -1,30 +1,40 @@
module SHL
class Request < RR
attr_accessor :verb, :url, :headers, :body
+
def url=(url)
- @url=URI.parse(url)
+ @url = URI.parse(url)
end
+
def path
- (@url.path=='')?'/':@url.path
+ @url.path == '' ? '/' : @url.path
end
+
def connection
- @connection||=TCPSocket.new(@url.host,@url.port)
+ @connection ||= TCPSocket.new(@url.host, @url.port)
end
+
def request_line
"#{verb.to_s.upcase} #{path} #{HTTP_VERSION}"
end
+
def headers
@headers||=OrderedHash.new([
['Host',@url.host],
['Connection','close']
])
end
+
def serialized_headers
- headers.map{|k,v|"#{k}: #{v}"}.join(NEWLINE)
+ headers.map do |key, value|
+ "#{key}: #{value}"
+ end.join(NEWLINE)
end
+
def serialized_body
- @body.to_s+NEWLINE
+ @body.to_s + NEWLINE
end
+
def run
connection.write([request_line,serialized_headers,serialized_body].join(NEWLINE))
connection.flush

0 comments on commit 0c7b88e

Please sign in to comment.