本文整理了Java中okhttp3.mockwebserver.MockWebServer.setProtocols()
方法的一些代码示例,展示了MockWebServer.setProtocols()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.setProtocols()
方法的具体详情如下:
包路径:okhttp3.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:setProtocols
[英]Indicates the protocols supported by ALPN on incoming HTTPS connections. This list is ignored when #setProtocolNegotiationEnabled.
[中]指示ALPN在传入HTTPS连接上支持的协议。当启用#setProtocolNegotiationEnabled时,此列表将被忽略。
代码示例来源:origin: square/okhttp
public void run() throws Exception {
File socketFile = new File("/tmp/ClientAndServer.sock");
socketFile.delete(); // Clean up from previous runs.
MockWebServer server = new MockWebServer();
server.setServerSocketFactory(new UnixDomainServerSocketFactory(socketFile));
server.setProtocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
server.enqueue(new MockResponse().setBody("hello"));
server.start();
OkHttpClient client = new OkHttpClient.Builder()
.socketFactory(new UnixDomainSocketFactory(socketFile))
.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE))
.build();
Request request = new Request.Builder()
.url("http://publicobject.com/helloworld.txt")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
server.shutdown();
socketFile.delete();
}
代码示例来源:origin: xjdr/xio
@Before
public void setUp() throws Exception {
log.debug("Test: " + testName.getMethodName());
client =
OkHttpUnsafe.getUnsafeClient()
.newBuilder()
.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1))
.build();
TlsConfig tlsConfig =
TlsConfig.builderFrom(ConfigFactory.load().getConfig("xio.h2BackendServer.settings.tls"))
.build();
server = OkHttpUnsafe.getSslMockWebServer(getKeyManagers(tlsConfig));
server.setProtocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
server.start();
}
代码示例来源:origin: xjdr/xio
@Before
public void setUp() throws Exception {
reportedSpans = new ArrayList<>();
TlsConfig tlsConfig =
TlsConfig.builderFrom(ConfigFactory.load().getConfig("xio.h2BackendServer.settings.tls"))
.build();
server = OkHttpUnsafe.getSslMockWebServer(getKeyManagers(tlsConfig));
server.setProtocols(Collections.singletonList(Protocol.HTTP_1_1));
server.enqueue(buildResponse());
server.start();
}
代码示例来源:origin: xjdr/xio
@Test
public void testConnectingSuccessfulConnection() throws Exception {
// set up fake origin backend server so we can connect to it, we connect to port 8888
// the outbound 8888 is specified in the ClientConnectionManagerIntegrationTest.conf
TlsConfig tlsConfig =
TlsConfig.builderFrom(ConfigFactory.load().getConfig("xio.h2BackendServer.settings.tls"))
.build();
server = OkHttpUnsafe.getSslMockWebServer(TlsHelper.getKeyManagers(tlsConfig));
server.setProtocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
// tell the server to bind to 8888
server.start(8888);
subject = subjectFactory(true);
Future<Void> connectionResult = subject.connect();
assertEquals(ClientConnectionState.CONNECTING, subject.connectionState());
Thread.sleep(100); // todo: (WK) do something smarter
try {
connectionResult.get(5, TimeUnit.SECONDS);
} catch (Exception e) {
System.out.println("Connection exception = " + e.toString());
} finally {
assertEquals(ClientConnectionState.CONNECTED, subject.connectionState());
server.close();
}
}
代码示例来源:origin: xjdr/xio
OkHttpUnsafe.getSslMockWebServer(
getKeyManagers(tlsConfig.getPrivateKey(), tlsConfig.getCertificateAndChain()));
server.setProtocols(protocols);
server.setDispatcher(
new Dispatcher() {
内容来源于网络,如有侵权,请联系作者删除!