use of okhttp3.HttpUrl in project okhttp by square.
the class CacheTest method iteratorRemoveFromCache.
@Test
public void iteratorRemoveFromCache() throws Exception {
// Put a response in the cache.
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").setBody("a"));
HttpUrl url = server.url("/a");
assertEquals("a", get(url).body().string());
// Remove it with iteration.
Iterator<String> i = cache.urls();
assertEquals(url.toString(), i.next());
i.remove();
// Confirm that subsequent requests suffer a cache miss.
server.enqueue(new MockResponse().setBody("b"));
assertEquals("b", get(url).body().string());
}
use of okhttp3.HttpUrl in project okhttp by square.
the class CacheTest method varyMultipleFieldsWithMatch.
@Test
public void varyMultipleFieldsWithMatch() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: Accept-Language, Accept-Charset").addHeader("Vary: Accept-Encoding").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
HttpUrl url = server.url("/");
Request request = new Request.Builder().url(url).header("Accept-Language", "fr-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").build();
Response response1 = client.newCall(request).execute();
assertEquals("A", response1.body().string());
Request request1 = new Request.Builder().url(url).header("Accept-Language", "fr-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").build();
Response response2 = client.newCall(request1).execute();
assertEquals("A", response2.body().string());
}
use of okhttp3.HttpUrl in project ExoPlayer by google.
the class OkHttpDataSource method makeRequest.
/**
* Establishes a connection.
*/
private Request makeRequest(DataSpec dataSpec) {
long position = dataSpec.position;
long length = dataSpec.length;
boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);
HttpUrl url = HttpUrl.parse(dataSpec.uri.toString());
Request.Builder builder = new Request.Builder().url(url);
if (cacheControl != null) {
builder.cacheControl(cacheControl);
}
if (defaultRequestProperties != null) {
for (Map.Entry<String, String> property : defaultRequestProperties.getSnapshot().entrySet()) {
builder.header(property.getKey(), property.getValue());
}
}
for (Map.Entry<String, String> property : requestProperties.getSnapshot().entrySet()) {
builder.header(property.getKey(), property.getValue());
}
if (!(position == 0 && length == C.LENGTH_UNSET)) {
String rangeRequest = "bytes=" + position + "-";
if (length != C.LENGTH_UNSET) {
rangeRequest += (position + length - 1);
}
builder.addHeader("Range", rangeRequest);
}
builder.addHeader("User-Agent", userAgent);
if (!allowGzip) {
builder.addHeader("Accept-Encoding", "identity");
}
if (dataSpec.postBody != null) {
builder.post(RequestBody.create(null, dataSpec.postBody));
}
return builder.build();
}
use of okhttp3.HttpUrl in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method removeCookie.
@OnClick(R.id.removeCookie)
public void removeCookie(View view) {
HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
cookieStore.removeCookie(httpUrl);
showToast("详细移除cookie的代码,请看demo的代码");
}
use of okhttp3.HttpUrl in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method getCookie.
@OnClick(R.id.getCookie)
public void getCookie(View view) {
//一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
List<Cookie> cookies = cookieStore.getCookie(httpUrl);
showToast(httpUrl.host() + "对应的cookie如下:" + cookies.toString());
}
Aggregations