Created
August 3, 2012 09:07
-
-
Save commuterjoy/3246120 to your computer and use it in GitHub Desktop.
Override host header with HTMLUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium._ | |
import org.openqa.selenium.htmlunit._ | |
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatest.{ GivenWhenThen, FeatureSpec } | |
import test.`package`._ | |
// instance of htmlunit with request header setting ability | |
class FixedHtmlUnitDriver extends HtmlUnitDriver { | |
def setHeader(name: String, value: String) = { | |
getWebClient().addRequestHeader(name, value) | |
} | |
} | |
// | |
class HostOverrideTest extends FeatureSpec { | |
val driver = new FixedHtmlUnitDriver | |
driver.setHeader("X-Edition-Override", "usa") | |
driver.setHeader("Host", "example.com") | |
driver.get("http://localhost:4567/hello") | |
println(driver.getTitle()) | |
println(driver.getPageSource()) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
get "/hello" do || | |
request.env["HTTP_HOST"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, please can you help me in doing this in java, it does not work.
On doing, it throws the following exception:
Thread-15] c.g.h.j.DefaultJavaScriptErrorListener : Error loading JavaScript from [https://code.jquery.com/jquery-latest.min.js]
Basically, it does not download any resource such as javascript.