Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow http HEAD requests #55

Closed
wants to merge 1 commit into from

2 participants

Andrew Humphrey ahumphrey
Andrew Humphrey

I was writing cucumber-nagios tests and wanted to test that a redirect was working as expected.

The cleaest way I could think of was to do a HEAD request on the resource and check the Location header but t do that I needed webrat to make HEAD requests and not automatically follow the redirect that is returned. This seemed better than hacking in an option to not follow the redirect on any request type.

Cheers,
Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2011
  1. ahumphrey

    Allow HEAD request type

    ahumphrey authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +4 −0 lib/webrat/adapters/mechanize.rb
  2. +3 −2 lib/webrat/core/session.rb
4 lib/webrat/adapters/mechanize.rb
View
@@ -20,6 +20,10 @@ def get(url, data, headers_argument_not_used = nil)
@response = mechanize.get(url, data)
end
+ def head(url, data, headers_argument_not_used = nil)
+ @response = mechanize.head(url, data)
+ end
+
def post(url, data, headers_argument_not_used = nil)
post_data = data.inject({}) do |memo, param|
case param
5 lib/webrat/core/session.rb
View
@@ -67,7 +67,7 @@ class Session
def_delegators :@adapter, :response, :response_code, :response_body, :response_headers,
:response_body=, :response_code=,
- :get, :post, :put, :delete
+ :get, :post, :put, :delete, :head
def initialize(adapter = nil)
@adapter = adapter
@@ -127,7 +127,8 @@ def request_page(url, http_method, data) #:nodoc:
@http_method = http_method
@data = data
- if internal_redirect?
+ # Do not follow redirects for HEAD requests
+ if internal_redirect? and http_method != 'head'
check_for_infinite_redirects
request_page(response_location, :get, {})
end
Something went wrong with that request. Please try again.