use of okhttp3.HttpUrl in project connect-android-sdk by telenordigital.
the class ConnectUrlHelperTest method webViewBrowserTypeOnGetAuthorizeUriReturnsWebViewParam.
@Test
public void webViewBrowserTypeOnGetAuthorizeUriReturnsWebViewParam() {
HttpUrl url = new HttpUrl.Builder().scheme("https").host("connect.telenordigital.com").build();
ArrayList<String> locales = new ArrayList<>();
locales.add(Locale.ENGLISH.getLanguage());
HashMap<String, String> parameters = new HashMap<>();
Uri authorizeUri = ConnectUrlHelper.getAuthorizeUriStem(parameters, "client-id-example", "redirect-url://here", locales, url, BrowserType.WEB_VIEW);
assertThat(authorizeUri.getQueryParameter("telenordigital_sdk_version").endsWith("web-view"), is(true));
}
use of okhttp3.HttpUrl in project nzbhydra2 by theotherp.
the class ReleaseMojoTest method testExecute.
public void testExecute() throws Exception {
MockWebServer server = getMockWebServer();
HttpUrl url = server.url("/repos/theotherp/nzbhydra2/releases");
// Here the magic happens
File pom = getTestFile("/src/test/resources/org/nzbhydra/github/mavenreleaseplugin/pomWithToken.xml");
assertTrue(pom.exists());
ReleaseMojo releaseMojo = new ReleaseMojo();
releaseMojo = (ReleaseMojo) configureMojo(releaseMojo, extractPluginConfiguration("github-release-plugin", pom));
releaseMojo.githubReleasesUrl = url.toString();
releaseMojo.windowsAsset = getTestFile("src/test/resources/org/nzbhydra/github/mavenreleaseplugin/windowsAsset.txt");
releaseMojo.linuxAsset = getTestFile("src/test/resources/org/nzbhydra/github/mavenreleaseplugin/linuxAsset.txt");
releaseMojo.execute();
verifyExecution(server);
}
use of okhttp3.HttpUrl in project edx-app-android by edx.
the class NoCacheHeaderStrippingInterceptor method intercept.
@NonNull
@Override
public Response intercept(@NonNull final Chain chain) throws IOException {
final Request request = chain.request();
final Response response = chain.proceed(request);
final Headers headers = response.headers();
Headers.Builder strippedHeadersBuilder = null;
List<String> headersToStrip = null;
for (int i = 0, headersCount = headers.size(); i < headersCount; i++) {
final String headerName = headers.name(i);
final String headerValue = headers.value(i);
if (headerName.equalsIgnoreCase("Cache-Control")) {
Matcher directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(headerValue);
if (directiveMatcher.find()) {
if (strippedHeadersBuilder == null) {
strippedHeadersBuilder = new Headers.Builder();
for (int j = 0; j < i; j++) {
strippedHeadersBuilder.add(headers.name(j), headers.value(j));
}
headersToStrip = new ArrayList<>();
}
String newHeaderValue = headerValue;
while (true) {
Collections.addAll(headersToStrip, directiveMatcher.group(GROUP_NO_CACHE_HEADERS).trim().split("\\s*,\\s*"));
final StringBuffer newHeaderValueBuffer = new StringBuffer();
directiveMatcher.appendReplacement(newHeaderValueBuffer, "$" + (directiveMatcher.group(GROUP_SEPARATOR_START).isEmpty() ? GROUP_SEPARATOR_END : GROUP_SEPARATOR_START));
directiveMatcher.appendTail(newHeaderValueBuffer);
newHeaderValue = newHeaderValueBuffer.toString();
directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(newHeaderValue);
if (!directiveMatcher.find())
break;
}
if (!newHeaderValue.isEmpty()) {
strippedHeadersBuilder.add(headerName, newHeaderValue);
}
continue;
}
}
if (strippedHeadersBuilder != null) {
strippedHeadersBuilder.add(headerName, headerValue);
}
}
if (strippedHeadersBuilder == null) {
return response;
}
final HttpUrl url = request.url();
List<Cookie> cookies = null;
for (final String headerToStrip : headersToStrip) {
strippedHeadersBuilder.removeAll(headerToStrip);
if (headerToStrip.equalsIgnoreCase("Set-Cookie")) {
if (cookieJar != CookieJar.NO_COOKIES) {
for (final String cookieString : headers.values(headerToStrip)) {
Cookie cookie = Cookie.parse(url, cookieString);
if (cookie != null) {
if (cookies == null) {
cookies = new ArrayList<>();
}
cookies.add(cookie);
}
}
}
}
}
if (cookies != null) {
cookieJar.saveFromResponse(url, cookies);
}
return response.newBuilder().headers(strippedHeadersBuilder.build()).build();
}
use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.
the class PaginationTypeAdapter method read.
/*
* (non-Javadoc)
* @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
*/
@Override
public Pagination read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
reader.beginObject();
Pagination pagination = new Pagination();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals(REFRESH_URL)) {
pagination.setRefreshUrl(reader.nextString());
} else if (name.equals(NEXT_URL)) {
String nextUrl = reader.nextString();
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
pagination.setCursor(url.queryParameter(CURSOR));
pagination.setNextUrl(nextUrl);
} else if (name.equals(TOTAL)) {
pagination.setTotal(reader.nextLong());
} else if (name.equals(MATCHED)) {
pagination.setMatched(reader.nextLong());
} else {
reader.skipValue();
}
}
reader.endObject();
return pagination;
}
use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.
the class WatsonCookieJar method loadForRequest.
/*
* (non-Javadoc)
*
* @see okhttp3.CookieJar#loadForRequest(okhttp3.HttpUrl)
*/
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
List<Cookie> cookies = this.adapter.loadForRequest(url);
// TODO: Removes the SESSIONID for speech to text session lest requests
if (url.encodedPathSegments().contains(SPEECH_TO_TEXT) && !url.encodedPathSegments().contains(SESSIONS)) {
List<Cookie> sessionLessCookies = new ArrayList<Cookie>();
for (Cookie cookie : cookies) {
if (!cookie.name().equalsIgnoreCase(SESSIONID)) {
sessionLessCookies.add(cookie);
}
}
cookies = sessionLessCookies;
}
return cookies;
}
Aggregations