From 3f39c9d9bd32e1e892affc48dc973bb6e9778d01 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Mon, 3 May 2021 13:28:34 +0900 Subject: [PATCH] treat uri as URI --- src/mechanize/file.cr | 2 +- src/mechanize/http/agent.cr | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mechanize/file.cr b/src/mechanize/file.cr index 423db3d..72aa084 100644 --- a/src/mechanize/file.cr +++ b/src/mechanize/file.cr @@ -2,7 +2,7 @@ require "http/client" class MechanizeCr::File #property :body, :filename 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 @body = body @code = code diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index 2f7f0c1..a795c6a 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -12,16 +12,15 @@ module MechanizeCr end def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new) + uri = URI.parse(uri) add_request_headers(headers) params = hash_to_params(params) response = http_request uri, method, params body = response.not_nil!.body page = response_parse(response, body, uri) - puts page.code end def http_request(uri, method, params) - uri = URI.parse(uri) request = ::HTTP::Client.new(uri.host.not_nil!) path = compose_path(uri, params) case uri.scheme.not_nil!.downcase @@ -49,7 +48,7 @@ module MechanizeCr path end - private def response_parse (response, body, uri) + private def response_parse(response, body, uri) @context.not_nil!.parse uri, response, body end end