complete uri scheme from referer_uri
parent
98ac971e31
commit
0baedaca6e
|
@ -4,6 +4,8 @@ WebMock.stub(:post, "http://example.com/post")
|
|||
.with(body: "email=foobar", headers: {"Content-Type" => "application/x-www-form-urlencoded"})
|
||||
.to_return(body: "success")
|
||||
WebMock.stub(:get, "example.com/%E3%81%82%E3%81%82%E3%81%82")
|
||||
WebMock.stub(:get, "https://example.com/")
|
||||
WebMock.stub(:get, "https://example.com/post")
|
||||
|
||||
describe "Mechanize HTTP test" do
|
||||
it "simple GET" do
|
||||
|
@ -62,4 +64,11 @@ describe "Mechanize HTTP test" do
|
|||
page = agent.get("http://example.com/")
|
||||
agent.request_headers["User-Agent"].should eq mac_chrome_agent
|
||||
end
|
||||
|
||||
it "can complete uri when uri is relative" do
|
||||
agent = Mechanize.new
|
||||
agent.get("https://example.com/")
|
||||
page = agent.get("/post")
|
||||
page.uri.to_s.should eq "https://example.com/post"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,10 +151,16 @@ module MechanizeCr
|
|||
if target_url.host.nil? && referer && referer_uri.try &.host
|
||||
target_url.host = referer_uri.not_nil!.host
|
||||
end
|
||||
|
||||
# fill scheme if scheme isn't set
|
||||
if target_url.relative?
|
||||
target_url.scheme = "http"
|
||||
if referer && referer_uri.try &.scheme
|
||||
target_url.scheme = referer_uri.not_nil!.scheme
|
||||
else
|
||||
target_url.scheme = "http"
|
||||
end
|
||||
end
|
||||
|
||||
# fill path's slash if there's no slash.
|
||||
if target_url.path && (target_url.path.empty? || target_url.path[0] != '/')
|
||||
target_url.path = "/#{target_url.path}"
|
||||
|
|
Loading…
Reference in New Issue