Example usage for com.squareup.okhttp Protocol HTTP_2

List of usage examples for com.squareup.okhttp Protocol HTTP_2

Introduction

In this page you can find the example usage for com.squareup.okhttp Protocol HTTP_2.

Prototype

Protocol HTTP_2

To view the source code for com.squareup.okhttp Protocol HTTP_2.

Click Source Link

Document

The IETF's binary-framed protocol that includes header compression, multiplexing multiple requests on the same socket, and server-push.

Usage

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java

License:Open Source License

private ServiceFilter getTestFilter(final int statusCode, final String content) {
    return new ServiceFilter() {

        @Override/* w w  w.j  a va2 s.  c  o  m*/
        public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
                NextServiceFilterCallback nextServiceFilterCallback) {

            // Create a mock response simulating an error
            ServiceFilterResponseMock response = new ServiceFilterResponseMock();
            response.setStatus((new StatusLine(Protocol.HTTP_2, statusCode, "")));
            response.setContent(content);

            // create a mock request to replace the existing one
            ServiceFilterRequestMock requestMock = new ServiceFilterRequestMock(response);
            return nextServiceFilterCallback.onNext(requestMock);
        }
    };
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.MockResponse.java

License:Open Source License

public MockResponse(String content, int statusCode) {
    mStatus = new StatusLine(Protocol.HTTP_2, statusCode, "");
    mContent = content.getBytes();
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.MockResponse.java

License:Open Source License

public MockResponse(byte[] content, int statusCode) {
    mStatus = new StatusLine(Protocol.HTTP_2, statusCode, "");
    mContent = content;
}

From source file:twitter4j.AlternativeHttpClientImpl.java

License:Apache License

private void prepareOkHttpClient() {
    if (okHttpClient == null) {
        okHttpClient = new OkHttpClient();

        //set protocols
        List<Protocol> protocols = new ArrayList<Protocol>();
        protocols.add(Protocol.HTTP_1_1);
        if (sPreferHttp2)
            protocols.add(Protocol.HTTP_2);
        if (sPreferSpdy)
            protocols.add(Protocol.SPDY_3);
        okHttpClient.setProtocols(protocols);

        //connectionPool setup
        okHttpClient.setConnectionPool(new ConnectionPool(MAX_CONNECTIONS, KEEP_ALIVE_DURATION_MS));

        //redirect disable
        okHttpClient.setFollowSslRedirects(false);

        //for proxy
        if (isProxyConfigured()) {
            if (CONF.getHttpProxyUser() != null && !CONF.getHttpProxyUser().equals("")) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Proxy AuthUser: " + CONF.getHttpProxyUser());
                    logger.debug("Proxy AuthPassword: " + CONF.getHttpProxyPassword().replaceAll(".", "*"));
                }// w  w w  . j av  a  2s.c  o  m
                Authenticator.setDefault(new Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        if (getRequestorType().equals(RequestorType.PROXY)) {
                            return new PasswordAuthentication(CONF.getHttpProxyUser(),
                                    CONF.getHttpProxyPassword().toCharArray());
                        } else {
                            return null;
                        }
                    }
                });
            }
            final Proxy proxy = new Proxy(Proxy.Type.HTTP,
                    InetSocketAddress.createUnresolved(CONF.getHttpProxyHost(), CONF.getHttpProxyPort()));
            if (logger.isDebugEnabled()) {
                logger.debug("Opening proxied connection(" + CONF.getHttpProxyHost() + ":"
                        + CONF.getHttpProxyPort() + ")");
            }
            okHttpClient.setProxy(proxy);
        }

        //connection timeout
        if (CONF.getHttpConnectionTimeout() > 0) {
            okHttpClient.setConnectTimeout(CONF.getHttpConnectionTimeout(), TimeUnit.MILLISECONDS);
        }

        //read timeout
        if (CONF.getHttpReadTimeout() > 0) {
            okHttpClient.setReadTimeout(CONF.getHttpReadTimeout(), TimeUnit.MILLISECONDS);
        }
    }
}