Search in sources :

Example 71 with HttpUrl

use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.

the class EnqueueResourcesMockWebServerITest method contentType.

@Test
public void contentType() throws IOException {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals("application/json", response.headers().get("Content-Type"));
    assertEquals("{'message':'hi'}", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 72 with HttpUrl

use of okhttp3.HttpUrl in project RxReddit by damien5314.

the class RawResponseInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request originalRequest = chain.request();
    HttpUrl url = originalRequest.url().newBuilder().addQueryParameter("raw_json", "1").build();
    Request newRequest = originalRequest.newBuilder().url(url).build();
    return chain.proceed(newRequest);
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 73 with HttpUrl

use of okhttp3.HttpUrl in project TeamCityApp by vase4kin.

the class GuestUserAuthInterceptor method intercept.

/**
 * {@inheritDoc}
 */
@Override
public Response intercept(Chain chain) throws IOException {
    HttpUrl urlWithGuestSupport = chain.request().url().newBuilder().addQueryParameter(QUERY_PARAM, QUERY_VALUE).build();
    Request requestWithGuestSupport = chain.request().newBuilder().url(urlWithGuestSupport).build();
    return chain.proceed(requestWithGuestSupport);
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 74 with HttpUrl

use of okhttp3.HttpUrl in project drift-sdk-android by Driftt.

the class APIAuthTokenInterceptor method intercept.

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
    Request request = chain.request();
    Auth auth = Auth.getInstance();
    if (auth != null && auth.getAccessToken() != null) {
        HttpUrl url = request.url().newBuilder().addQueryParameter("access_token", auth.getAccessToken()).build();
        request = request.newBuilder().url(url).build();
    }
    return chain.proceed(request);
}
Also used : Auth(drift.com.drift.model.Auth) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 75 with HttpUrl

use of okhttp3.HttpUrl in project mapbox-events-android by mapbox.

the class MockWebServerTest method provideDefaultTelemetryClientSettings.

private TelemetryClientSettings provideDefaultTelemetryClientSettings() {
    HttpUrl localUrl = obtainBaseEndpointUrl();
    SslClient sslClient = SslClient.localhost();
    return new TelemetryClientSettings.Builder().baseUrl(localUrl).sslSocketFactory(sslClient.socketFactory).x509TrustManager(sslClient.trustManager).hostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }).build();
}
Also used : SslClient(okhttp3.mockwebserver.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) HttpUrl(okhttp3.HttpUrl) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

HttpUrl (okhttp3.HttpUrl)302 Request (okhttp3.Request)130 Test (org.junit.Test)86 Response (okhttp3.Response)69 IOException (java.io.IOException)61 MockResponse (okhttp3.mockwebserver.MockResponse)40 Cookie (okhttp3.Cookie)35 ArrayList (java.util.ArrayList)28 OkHttpClient (okhttp3.OkHttpClient)27 MockWebServer (okhttp3.mockwebserver.MockWebServer)26 InputStream (java.io.InputStream)21 InputStreamReader (java.io.InputStreamReader)20 HashMap (java.util.HashMap)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 RequestBody (okhttp3.RequestBody)18 JsonParseException (com.google.gson.JsonParseException)13 File (java.io.File)12 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)10 List (java.util.List)10 Test (org.junit.jupiter.api.Test)10