treat uri as URI
This commit is contained in:
parent
803e242035
commit
3f39c9d9bd
@ -2,7 +2,7 @@ require "http/client"
|
|||||||
class MechanizeCr::File
|
class MechanizeCr::File
|
||||||
#property :body, :filename
|
#property :body, :filename
|
||||||
property :body, :code
|
property :body, :code
|
||||||
def initialize(uri : String | Nil, response : ::HTTP::Client::Response | Nil, body : String , code : Int32 | Nil)
|
def initialize(uri : URI | Nil, response : ::HTTP::Client::Response | Nil, body : String , code : Int32 | Nil)
|
||||||
@uri = uri
|
@uri = uri
|
||||||
@body = body
|
@body = body
|
||||||
@code = code
|
@code = code
|
||||||
|
@ -12,16 +12,15 @@ module MechanizeCr
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new)
|
def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new)
|
||||||
|
uri = URI.parse(uri)
|
||||||
add_request_headers(headers)
|
add_request_headers(headers)
|
||||||
params = hash_to_params(params)
|
params = hash_to_params(params)
|
||||||
response = http_request uri, method, params
|
response = http_request uri, method, params
|
||||||
body = response.not_nil!.body
|
body = response.not_nil!.body
|
||||||
page = response_parse(response, body, uri)
|
page = response_parse(response, body, uri)
|
||||||
puts page.code
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_request(uri, method, params)
|
def http_request(uri, method, params)
|
||||||
uri = URI.parse(uri)
|
|
||||||
request = ::HTTP::Client.new(uri.host.not_nil!)
|
request = ::HTTP::Client.new(uri.host.not_nil!)
|
||||||
path = compose_path(uri, params)
|
path = compose_path(uri, params)
|
||||||
case uri.scheme.not_nil!.downcase
|
case uri.scheme.not_nil!.downcase
|
||||||
@ -49,7 +48,7 @@ module MechanizeCr
|
|||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
private def response_parse (response, body, uri)
|
private def response_parse(response, body, uri)
|
||||||
@context.not_nil!.parse uri, response, body
|
@context.not_nil!.parse uri, response, body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user