Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

domain resolved by mruby-uv

  • Loading branch information...
commit 799fafeacba0d2447dc29af4fa798cbd0010e8f4 1 parent 9b4e032
@matsumoto-r authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 mrblib/simplehttp.rb
View
12 mrblib/simplehttp.rb
@@ -6,7 +6,15 @@ class SimpleHttp
def initialize(address, port = DEFAULTPORT)
@uri = {}
+ ip = ""
+ UV::getaddrinfo(address, "http") do |x, info|
+ if info
+ ip = info.addr
+ end
+ end
+ UV::run()
@uri[:address] = address
+ @uri[:ip] = ip
@uri[:port] = port ? port.to_i : DEFAULTPORT
self
end
@@ -34,11 +42,10 @@ def request(method, path, req)
response_text = send_request(request_header)
SimpleHttpResponse.new(response_text)
end
-
def send_request(request_header)
socket = UV::TCP.new()
response_text = ""
- socket.connect(UV.ip4_addr(@uri[:address], @uri[:port])) do |x|
+ socket.connect(UV.ip4_addr(@uri[:ip], @uri[:port])) do |x|
if x == 0
socket.write(request_header) do |x|
socket.read_start do |b|
@@ -49,6 +56,7 @@ def send_request(request_header)
socket.close()
end
end
+
UV::run()
response_text
end
Please sign in to comment.
Something went wrong with that request. Please try again.