41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/async2/http.rb', line 41
def request(uri, verb = "GET", = {}, body = nil)
uri = URI.parse uri
uri.path = "/" if uri.path == ""
["User-Agent"] = "ruby/#{RUBY_VERSION}"
["Host"] = uri.hostname
["Accept"] = "*/*"
buffer = "#{verb} #{uri.path} HTTP/1.1\r\n" + .map { |k, v| "#{k}: #{v}" }.join("\r\n") + "\r\n\r\n"
buffer += "\r\n#{body}" if body
socket = TCPSocket.new uri.hostname, uri.port
p "client> #{buffer}"
socket.print buffer
Async2.instance.read(socket) do
buff = read_all(socket)
rep, body = to_response(buff, socket)
yield body, rep, buff
end
end
|