From 8358e55af08f82832b8b7c21c8570cdd2eec0478 Mon Sep 17 00:00:00 2001 From: Patrick Lohan <35260408+PatrickLohan@users.noreply.github.com> Date: Fri, 19 Feb 2021 10:43:56 +0000 Subject: [PATCH 1/3] Update demo scripts with correct path Scripts were using ../demo but needs ./demo. Fixed and tested on android --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 35d15f2..816c5f4 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "build.ios": "bash src-native/ios/build.sh", "build.native": "npm run build.android && npm run build.ios", "build": "npm run build.plugin", - "demo.ios": "npm run build && cd ../demo && tns run ios", - "demo.android": "npm run build && cd ../demo && tns run android", + "demo.ios": "npm run build && cd ./demo && tns run ios", + "demo.android": "npm run build && cd ./demo && tns run android", "plugin.watch.tsc": "npm run tsc -- -w", "plugin.watch.android": "npm i && npm-watch build.android", "plugin.watch.ios": "npm i && npm-watch build.ios", @@ -96,4 +96,4 @@ "@commitlint/config-conventional" ] } -} \ No newline at end of file +} From cc225bea37e0035288533106e48a469e11d15d01 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Sun, 14 Mar 2021 20:54:13 +0100 Subject: [PATCH 2/3] feat(android): forceCache option --- .../nativescript/https/CacheInterceptor.java | 18 ++++++++++++++++++ src/https.android.ts | 6 +++++- src/https.common.ts | 1 + src/typings/android.d.ts | 3 +++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 plugin/platforms/android/java/com/nativescript/https/CacheInterceptor.java diff --git a/plugin/platforms/android/java/com/nativescript/https/CacheInterceptor.java b/plugin/platforms/android/java/com/nativescript/https/CacheInterceptor.java new file mode 100644 index 0000000..3797d80 --- /dev/null +++ b/plugin/platforms/android/java/com/nativescript/https/CacheInterceptor.java @@ -0,0 +1,18 @@ +package com.nativescript.https; +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; +import java.io.IOException; + +public class CacheInterceptor implements Interceptor { + final String TAG = "CacheInterceptor"; + + public Response intercept(Interceptor.Chain chain ) throws IOException { + Request originalRequest = chain.request(); + String cacheControlHeader = originalRequest.header("Cache-Control"); + Response originalResponse = chain.proceed(originalRequest); + return originalResponse.newBuilder().header("Cache-Control", cacheControlHeader).build(); + } + + +} \ No newline at end of file diff --git a/src/https.android.ts b/src/https.android.ts index 2a17285..b4255a1 100644 --- a/src/https.android.ts +++ b/src/https.android.ts @@ -18,9 +18,10 @@ const peer: Ipeer = { }; let cache: okhttp3.Cache; - +let forceCache = false; export function setCache(options?: Https.CacheOptions) { if (options) { + forceCache = options.forceCache === true; cache = new okhttp3.Cache(new java.io.File(options.diskLocation), options.diskSize); } else { cache = null; @@ -329,6 +330,9 @@ function getClient(reload: boolean = false, timeout: number = 10): okhttp3.OkHtt if (cache) { client.cache(cache); + if (forceCache) { + client.addInterceptor(new com.nativescript.https.CacheInterceptor()); + } } if (cookieJar) { client.cookieJar(cookieJar); diff --git a/src/https.common.ts b/src/https.common.ts index 1c81af5..80e10be 100644 --- a/src/https.common.ts +++ b/src/https.common.ts @@ -11,6 +11,7 @@ export interface CacheOptions { diskLocation: string; diskSize: number; memorySize?: number; + forceCache?: boolean; } export interface HttpsFormDataParam { diff --git a/src/typings/android.d.ts b/src/typings/android.d.ts index 89982be..e4d67ee 100644 --- a/src/typings/android.d.ts +++ b/src/typings/android.d.ts @@ -4,6 +4,9 @@ declare namespace com { export class QuotePreservingCookieJar extends okhttp3.CookieJar { constructor(manager: java.net.CookieManager); } + export class CacheInterceptor implements okhttp3.Interceptor { + intercept(chain): okhttp3.Response; + } export class OkHttpResponse { progressCallback: OkHttpResponse.OkHttpResponseProgressCallback; closeCallback: OkHttpResponse.OkHttpResponseCloseCallback; From d1119a919e6b786fdabc78b5e3a91d2ec3965e50 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Sun, 14 Mar 2021 20:55:26 +0100 Subject: [PATCH 3/3] v3.2.0 --- CHANGELOG.md | 11 +++++++++++ lerna.json | 2 +- plugin/CHANGELOG.md | 11 +++++++++++ plugin/package.json | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80cc7f5..8962a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.2.0](https://github.com/farfromrefug/nativescript-https/compare/v3.1.3...v3.2.0) (2021-03-14) + + +### Features + +* **android:** forceCache option ([cc225be](https://github.com/farfromrefug/nativescript-https/commit/cc225bea37e0035288533106e48a469e11d15d01)) + + + + + ## [3.1.3](https://github.com/farfromrefug/nativescript-https/compare/v3.1.2...v3.1.3) (2021-03-12) diff --git a/lerna.json b/lerna.json index 0516ed9..529473f 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "plugin" ], - "version": "3.1.3", + "version": "3.2.0", "command": { "publish": { "conventionalCommits": true diff --git a/plugin/CHANGELOG.md b/plugin/CHANGELOG.md index f804fc3..61a407b 100644 --- a/plugin/CHANGELOG.md +++ b/plugin/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.2.0](https://github.com/farfromrefug/nativescript-https/compare/v3.1.3...v3.2.0) (2021-03-14) + + +### Features + +* **android:** forceCache option ([cc225be](https://github.com/farfromrefug/nativescript-https/commit/cc225bea37e0035288533106e48a469e11d15d01)) + + + + + ## [3.1.3](https://github.com/farfromrefug/nativescript-https/compare/v3.1.2...v3.1.3) (2021-03-12) **Note:** Version bump only for package @nativescript-community/https diff --git a/plugin/package.json b/plugin/package.json index 5f2227e..b9f2c10 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript-community/https", - "version": "3.1.3", + "version": "3.2.0", "description": "Nativescript plugin for gestures", "main": "https", "sideEffects": false,