Dbrant has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/402600 )
Change subject: Fix interception of WebView content with extended content-type header. ...................................................................... Fix interception of WebView content with extended content-type header. Background: We use a WebView to display article content, but we intercept the WebView's network requests by using a custom WebViewClient where we perform our own network transaction using OkHttp. Once we receive a response, we pass it back to the WebView by creating a WebResourceResponse object which contains the stream of bytes, as well as the encoding and mime-type of the bytes. The thing is: The WebResourceResponse object expects the mime-type parameter to be a pure mime-type string, that is "type/subtype", with nothing else appended to it. Whereas, we were incorrectly passing the entire "content-type" header, which contains the mime-type, plus additional possible parameters such as "charset" and "profile." This patch updates our code to extract only the mime-type from the content-type header, and correctly pass it into the WebResourceResponse, thereby fixing the issues that users are seeing with SVG math formulas, which were recently updated to contain a "charset" parameter in their content-type. Bug: T184347 Change-Id: I7e5417519e842995bb6a54a0ed6b22096827b67f --- M app/src/main/java/org/wikipedia/dataclient/okhttp/OkHttpWebViewClient.java 1 file changed, 11 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/00/402600/1 diff --git a/app/src/main/java/org/wikipedia/dataclient/okhttp/OkHttpWebViewClient.java b/app/src/main/java/org/wikipedia/dataclient/okhttp/OkHttpWebViewClient.java index aeddad3..14881c4 100644 --- a/app/src/main/java/org/wikipedia/dataclient/okhttp/OkHttpWebViewClient.java +++ b/app/src/main/java/org/wikipedia/dataclient/okhttp/OkHttpWebViewClient.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -35,7 +36,6 @@ private static final List<String> SUPPORTED_SCHEMES = Arrays.asList("http", "https"); private static final String HEADER_CONTENT_TYPE = "content-type"; - private static final String HEADER_CONTENT_ENCODING = "content-encoding"; private static final String CONTENT_TYPE_OGG = "application/ogg"; @NonNull public abstract WikiSite getWikiSite(); @@ -48,9 +48,11 @@ try { Response rsp = request(url); - return new WebResourceResponse(rsp.header(HEADER_CONTENT_TYPE), - rsp.header(HEADER_CONTENT_ENCODING), getInputStream(rsp)); - } catch (IOException e) { + // noinspection ConstantConditions + return new WebResourceResponse(rsp.body().contentType().type() + "/" + rsp.body().contentType().subtype(), + rsp.body().contentType().charset(Charset.defaultCharset()).toString(), + getInputStream(rsp)); + } catch (Exception e) { L.e(e); } return null; @@ -65,12 +67,14 @@ try { Response rsp = request(request.getUrl().toString()); - return new WebResourceResponse(rsp.header(HEADER_CONTENT_TYPE), - rsp.header(HEADER_CONTENT_ENCODING), rsp.code(), + // noinspection ConstantConditions + return new WebResourceResponse(rsp.body().contentType().type() + "/" + rsp.body().contentType().subtype(), + rsp.body().contentType().charset(Charset.defaultCharset()).toString(), + rsp.code(), StringUtils.defaultIfBlank(rsp.message(), "Unknown error"), toMap(rsp.headers()), getInputStream(rsp)); - } catch (IOException e) { + } catch (Exception e) { L.e(e); } return null; -- To view, visit https://gerrit.wikimedia.org/r/402600 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7e5417519e842995bb6a54a0ed6b22096827b67f Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits