Follow redirects when checking served_by_pages? #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A follow up to #13, this pull request makes the
served_by_pages?
redirect a bit more robust by actually following the location header of 30x redirects when checking if a given domain is in fact served by pages.Previously, when we got a 30x redirect, we just requested the URL again, which is fine for DNS records pointed directly to pages.
In the case of
management.cio.gov
, for example, they proxy an actually-pages-served site through nginx to add SSL, which means we improperly said it wasn't served by pages because we didn't follow the redirect from HTTP to HTTPS.To accomplish this, the check now uses Typhoeus, a wrapper for libcurl to handle the redirects a bit more robustly. I also pulled the
uri
andscheme
variables into their own private methods, and moved to a HEAD request (which Pages supports), to speed up the check a bit by not downloading the page body.Last, some of our existing
served_by_pages?
tests weren't actually checking if the site wasserved_by_pages?
, now fixed. Heck, one test,choosealicense.com
wasn't even pointing at a valid domain, yet the test still passed. We now actually look atserved_by_pages?
directly, rather thanvalid?
./cc @jdennes, @spraints, @konklone
Fixes #17.