Created
March 23, 2016 22:26
-
-
Save alexlehm/d0f401792f66b6aaa9aa to your computer and use it in GitHub Desktop.
HttpsConnectTest.java
This file contains 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.junit.Test; | |
import org.junit.runner.RunWith; | |
import io.vertx.core.Vertx; | |
import io.vertx.core.logging.Logger; | |
import io.vertx.core.logging.LoggerFactory; | |
import io.vertx.core.net.NetClient; | |
import io.vertx.core.net.NetSocket; | |
import io.vertx.ext.unit.Async; | |
import io.vertx.ext.unit.TestContext; | |
import io.vertx.ext.unit.junit.VertxUnitRunner; | |
/** | |
* @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a> | |
* | |
*/ | |
@RunWith(VertxUnitRunner.class) | |
public class HttpsConnectTest { | |
private final static Logger log = LoggerFactory.getLogger(HttpsConnectTest.class); | |
@Test | |
public void test(TestContext context) { | |
Async async = context.async(); | |
NetClient client = Vertx.vertx().createNetClient(); | |
client.connect(3128, "localhost", res -> { | |
if (res.succeeded()) { | |
NetSocket ns = res.result(); | |
ns.handler(buffer -> { | |
log.info("connect result \"" + buffer + "\""); | |
context.assertTrue(buffer.toString().startsWith("HTTP/1.0 200 ")); | |
ns.upgradeToSsl(v -> { | |
log.info("ssl finished"); | |
// for a real application the hostname of the cert should be checked here | |
ns.handler(buffer2 -> { | |
log.info("http result \"" + buffer2 + "\""); | |
async.complete(); | |
}); | |
ns.write("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n"); | |
}); | |
}); | |
ns.exceptionHandler(th -> { | |
context.fail(th); | |
}); | |
ns.write("xCONNECT www.google.com:443 HTTP/1.0\r\n\r\n"); | |
} else { | |
context.fail(res.cause()); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment