[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Update okhttp to 3.8.0

2017-06-12 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358138 )

Change subject: Update okhttp to 3.8.0
..


Update okhttp to 3.8.0

N.B. Involves a change to a modified bit of CacheDelegateInterceptor!
Please review carefully and test well!  Here's the relevant okhttp commit:

Invalidate the cache even if the response has no body.
https://github.com/square/okhttp/commit/c9496d350c0c3bb4b9d9571c3ab97181726561e2

Also of note:

Version 3.8.0

New: The response message is now non-null. This is the "Not Found" in the
status line "HTTP 404 Not Found". If you are building responses programma-
tically (with new Response.Builder()) you must now always supply a
message. An empty string "" is permitted. This value was never null on
responses returned by OkHttp itself, and it was an old mistake to permit
application code to omit a message.

Version 3.7.0

New: Connection coalescing. OkHttp may reuse HTTP/2 connections across
calls that share an IP address and HTTPS certificate, even if their domain
names are different.

New: MockWebServer's RecordedRequest exposes the requested HttpUrl with
getRequestUrl().

https://github.com/square/okhttp/blob/master/CHANGELOG.md

Change-Id: Ie2cc3bf806b7a6c45bc31a068fa4c64cecad51de
---
M app/build.gradle
M app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
2 files changed, 29 insertions(+), 36 deletions(-)

Approvals:
  Niedzielski: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/build.gradle b/app/build.gradle
index 98e1948..ccc4796 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -162,7 +162,7 @@
 // use http://gradleplease.appspot.com/ or http://search.maven.org/.
 // Debug with ./gradlew -q app:dependencies --configuration compile
 
-String okHttpVersion = '3.6.0' // When updating this version, resync file 
copies under
+String okHttpVersion = '3.8.0' // When updating this version, resync file 
copies under
// app/src/main/java/okhttp3
 String retrofitVersion = '2.2.0'
 String supportVersion = '25.3.1'
diff --git 
a/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java 
b/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
index 2e70b70..dd799ac 100644
--- a/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
+++ b/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
@@ -44,9 +44,15 @@
 import static okhttp3.internal.Util.closeQuietly;
 import static okhttp3.internal.Util.discard;
 
-/** Serves requests from the cache and writes responses to the cache. Copied 
from
- 
https://github.com/square/okhttp/blob/a27afaf/okhttp/src/main/java/okhttp3/internal/cache/CacheInterceptor.java
- to allow a custom cache strategy. Deviations are marked with "Change:". */
+/** Serves requests from the cache and writes responses to the cache. Copied 
from the OkHttp
+ repository (https://github.com/square/okhttp) to allow a custom cache 
strategy.
+
+ Last synchronized with OkHttp at the "parent-3.8.0" tag (last change: 
"Invalidate the cache even if
+ the response has no body." (c9496d3))
+
+ 
https://github.com/square/okhttp/blob/parent-3.8.0/okhttp/src/main/java/okhttp3/internal/cache/CacheInterceptor.java
+
+ Deviations are marked with "Change:". */
 public final class CacheDelegateInterceptor implements Interceptor {
   final InternalCache cache;
   // Change: add secondaryCache member variable
@@ -152,10 +158,23 @@
 .networkResponse(stripBody(networkResponse))
 .build();
 
-if (HttpHeaders.hasBody(response)) {
-  // Change: add cacheCandidate parameter
-  CacheRequest cacheRequest = maybeCache(cacheCandidate, response, 
networkResponse.request(), cache);
-  response = cacheWritingResponse(cacheRequest, response);
+if (cache != null) {
+  // Change: do not permit cache writes unless the page has been cached 
previously or the
+  // request is cacheable
+  if (HttpHeaders.hasBody(response) && CacheStrategy.isCacheable(response, 
networkRequest)
+  && (cacheCandidate != null || 
CacheDelegateStrategy.isCacheable(networkRequest))) {
+// Offer this request to the cache.
+CacheRequest cacheRequest = cache.put(response);
+return cacheWritingResponse(cacheRequest, response);
+  }
+
+  if (HttpMethod.invalidatesCache(networkRequest.method())) {
+try {
+  cache.remove(networkRequest);
+} catch (IOException ignored) {
+  // The cache cannot be written.
+}
+  }
 }
 
 return response;
@@ -163,35 +182,9 @@
 
   private static Response stripBody(Response response) {
 return response != null && response.body() != null
-? response.newBuilder().body(null).build()
-: response;
-  }
+? response.newBuilder().body(null).build()
+: response;
 
- 

[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Update okhttp to 3.8.0

2017-06-09 Thread Mholloway (Code Review)
Mholloway has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358138 )

Change subject: Update okhttp to 3.8.0
..

Update okhttp to 3.8.0

N.B. Involves a change to a modified bit of CacheDelegateInterceptor!
Please review carefully and test well!  Here's the relevant okhttp commit:

Invalidate the cache even if the response has no body.
https://github.com/square/okhttp/commit/c9496d350c0c3bb4b9d9571c3ab97181726561e2

Also of note:

Version 3.8.0

New: The response message is now non-null. This is the "Not Found" in the
status line "HTTP 404 Not Found". If you are building responses programma-
tically (with new Response.Builder()) you must now always supply a
message. An empty string "" is permitted. This value was never null on
responses returned by OkHttp itself, and it was an old mistake to permit
application code to omit a message.

Version 3.7.0

New: Connection coalescing. OkHttp may reuse HTTP/2 connections across
calls that share an IP address and HTTPS certificate, even if their domain
names are different.

New: MockWebServer's RecordedRequest exposes the requested HttpUrl with
getRequestUrl().

Change-Id: Ie2cc3bf806b7a6c45bc31a068fa4c64cecad51de
---
M app/build.gradle
M app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
2 files changed, 29 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/38/358138/1

diff --git a/app/build.gradle b/app/build.gradle
index 98e1948..ccc4796 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -162,7 +162,7 @@
 // use http://gradleplease.appspot.com/ or http://search.maven.org/.
 // Debug with ./gradlew -q app:dependencies --configuration compile
 
-String okHttpVersion = '3.6.0' // When updating this version, resync file 
copies under
+String okHttpVersion = '3.8.0' // When updating this version, resync file 
copies under
// app/src/main/java/okhttp3
 String retrofitVersion = '2.2.0'
 String supportVersion = '25.3.1'
diff --git 
a/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java 
b/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
index 2e70b70..df27cdd 100644
--- a/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
+++ b/app/src/main/java/okhttp3/internal/cache/CacheDelegateInterceptor.java
@@ -44,9 +44,15 @@
 import static okhttp3.internal.Util.closeQuietly;
 import static okhttp3.internal.Util.discard;
 
-/** Serves requests from the cache and writes responses to the cache. Copied 
from
- 
https://github.com/square/okhttp/blob/a27afaf/okhttp/src/main/java/okhttp3/internal/cache/CacheInterceptor.java
- to allow a custom cache strategy. Deviations are marked with "Change:". */
+/** Serves requests from the cache and writes responses to the cache. Copied 
from the OkHttp
+ repository (https://github.com/square/okhttp) to allow a custom cache 
strategy.
+
+ Last synchronized with OkHttp at the "parent-3.8.0" tag (last change: 
"Invalidate the cache even if
+ the response has no body." (c9496d3))
+
+ 
https://github.com/square/okhttp/blob/parent-3.8.0/okhttp/src/main/java/okhttp3/internal/cache/CacheInterceptor.java
+
+ Deviations are marked with "Change:". */
 public final class CacheDelegateInterceptor implements Interceptor {
   final InternalCache cache;
   // Change: add secondaryCache member variable
@@ -152,10 +158,23 @@
 .networkResponse(stripBody(networkResponse))
 .build();
 
-if (HttpHeaders.hasBody(response)) {
-  // Change: add cacheCandidate parameter
-  CacheRequest cacheRequest = maybeCache(cacheCandidate, response, 
networkResponse.request(), cache);
-  response = cacheWritingResponse(cacheRequest, response);
+if (cache != null) {
+  // Change: do not permit cache writes unless the page has been cached 
previously or the
+  // request is cacheable
+  if (HttpHeaders.hasBody(response) && CacheStrategy.isCacheable(response, 
networkRequest)
+  && !(cacheCandidate == null && 
!CacheDelegateStrategy.isCacheable(networkRequest))) {
+// Offer this request to the cache.
+CacheRequest cacheRequest = cache.put(response);
+return cacheWritingResponse(cacheRequest, response);
+  }
+
+  if (HttpMethod.invalidatesCache(networkRequest.method())) {
+try {
+  cache.remove(networkRequest);
+} catch (IOException ignored) {
+  // The cache cannot be written.
+}
+  }
 }
 
 return response;
@@ -163,35 +182,9 @@
 
   private static Response stripBody(Response response) {
 return response != null && response.body() != null
-? response.newBuilder().body(null).build()
-: response;
-  }
+? response.newBuilder().body(null).build()
+: response;
 
-  // Change: add cacheCandidate parameter
-  private