commit
9a2c0fbb33
|
@ -12,6 +12,7 @@ WebMock.stub(:put, "http://example.com/put")
|
||||||
WebMock.stub(:delete, "http://example.com/delete")
|
WebMock.stub(:delete, "http://example.com/delete")
|
||||||
.with(body: "hello")
|
.with(body: "hello")
|
||||||
.to_return(body: "success")
|
.to_return(body: "success")
|
||||||
|
WebMock.stub(:head, "http://example.com/head")
|
||||||
|
|
||||||
describe "Mechanize HTTP test" do
|
describe "Mechanize HTTP test" do
|
||||||
it "simple GET" do
|
it "simple GET" do
|
||||||
|
@ -61,6 +62,13 @@ describe "Mechanize HTTP test" do
|
||||||
page.code.should eq 200
|
page.code.should eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "HEAD" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
page = agent.head("http://example.com/head")
|
||||||
|
page.body.should eq ""
|
||||||
|
page.code.should eq 200
|
||||||
|
end
|
||||||
|
|
||||||
it "can escape non-ascii character" do
|
it "can escape non-ascii character" do
|
||||||
agent = Mechanize.new
|
agent = Mechanize.new
|
||||||
page = agent.get("http://example.com/あああ")
|
page = agent.get("http://example.com/あああ")
|
||||||
|
|
|
@ -135,6 +135,23 @@ class Mechanize
|
||||||
page
|
page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Send HEAD request to specified uri with headers.
|
||||||
|
#
|
||||||
|
# Examples (send HEAD request to http://example.com/)
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# agent = Mechanize.new
|
||||||
|
# agent.head("http://example.com")
|
||||||
|
# ```
|
||||||
|
def head(uri : String | URI,
|
||||||
|
headers = ::HTTP::Headers.new) : Mechanize::Page
|
||||||
|
method = :head
|
||||||
|
page = @agent.fetch uri, method, headers
|
||||||
|
add_to_history(page)
|
||||||
|
# yield page if block_given?
|
||||||
|
page
|
||||||
|
end
|
||||||
|
|
||||||
# get the value of request headers.
|
# get the value of request headers.
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
|
|
|
@ -76,6 +76,8 @@ class Mechanize
|
||||||
::HTTP::Client.put(uri, headers: request_headers, body: body)
|
::HTTP::Client.put(uri, headers: request_headers, body: body)
|
||||||
when :delete
|
when :delete
|
||||||
::HTTP::Client.delete(uri, headers: request_headers, body: body)
|
::HTTP::Client.delete(uri, headers: request_headers, body: body)
|
||||||
|
when :head
|
||||||
|
::HTTP::Client.head(uri, headers: request_headers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue