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