diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be7b4f..75facbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.4.3](https://github.com/nativescript-community/https/compare/v3.4.2...v3.4.3) (2022-04-25) + + +### Bug Fixes + +* **android:** native-api-usage fix ([bc3c7d2](https://github.com/nativescript-community/https/commit/bc3c7d24160038f48e487918ee8abcf5d24f0322)) + + +### Features + +* contentLength ([a2e1017](https://github.com/nativescript-community/https/commit/a2e10170145a8e94e10f407e5fe772cb0d40e12c)) + + + + + ## [3.4.2](https://github.com/nativescript-community/https/compare/v3.4.1...v3.4.2) (2022-02-26) diff --git a/lerna.json b/lerna.json index 1485893..4bc84e4 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "plugin" ], - "version": "3.4.2", + "version": "3.4.3", "command": { "publish": { "conventionalCommits": true diff --git a/package.json b/package.json index 3bab15f..ffde412 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,8 @@ "devDependencies": { "@commitlint/cli": "^9.1.2", "@commitlint/config-conventional": "^9.1.2", + "@lerna-lite/cli": "^1.0.5", + "@lerna-lite/run": "^1.0.5", "@nativescript-community/observable": "^2.0.8", "@nativescript/core": "7.0.0", "@nativescript/types-android": "7.0.2", @@ -69,7 +71,6 @@ "eslint-config-prettier": "^6.13.0", "eslint-plugin-prettier": "^3.1.4", "husky": "^4.2.5", - "lerna": "^3.22.1", "npm-watch": "^0.7.0", "prettier": "^2.1.2", "prompt": "^1.0.0", diff --git a/plugin/CHANGELOG.md b/plugin/CHANGELOG.md index 9f6074e..50b1e7b 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.4.3](https://github.com/nativescript-community/https/compare/v3.4.2...v3.4.3) (2022-04-25) + + +### Bug Fixes + +* **android:** native-api-usage fix ([bc3c7d2](https://github.com/nativescript-community/https/commit/bc3c7d24160038f48e487918ee8abcf5d24f0322)) + + + + + ## [3.4.2](https://github.com/nativescript-community/https/compare/v3.4.1...v3.4.2) (2022-02-26) **Note:** Version bump only for package @nativescript-community/https diff --git a/plugin/package.json b/plugin/package.json index a84128a..d63a35c 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript-community/https", - "version": "3.4.2", + "version": "3.4.3", "description": "Nativescript plugin for gestures", "main": "index", "sideEffects": false, diff --git a/plugin/platforms/android/native-api-usage.json b/plugin/platforms/android/native-api-usage.json index 1e40deb..9fe538a 100644 --- a/plugin/platforms/android/native-api-usage.json +++ b/plugin/platforms/android/native-api-usage.json @@ -38,6 +38,7 @@ "javax.net.ssl:TrustManagerFactory*", "javax.net.ssl:SSLContext*", "javax.net.ssl:HttpsURLConnection*", + "java.net:UnknownHostException*", "java.util.concurrent:TimeUnit*", "org.conscrypt:Conscrypt*" ] diff --git a/src/request.android.ts b/src/request.android.ts index fcb573d..e8b68a3 100644 --- a/src/request.android.ts +++ b/src/request.android.ts @@ -1,5 +1,5 @@ import { File, HttpResponseEncoding, ImageSource, Utils } from '@nativescript/core'; -import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponseLegacy, HttpsSSLPinningOptions } from '.'; +import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsSSLPinningOptions, HttpsResponseLegacy as IHttpsResponseLegacy } from '.'; import { getFilenameFromUrl, interceptors, networkInterceptors, parseJSON } from './request.common'; export { addNetworkInterceptor, addInterceptor } from './request.common'; @@ -41,10 +41,13 @@ export function clearCache() { let _timeout = 10; -class HttpsResponseLegacyIOS implements HttpsResponseLegacy { +class HttpsResponseLegacy implements IHttpsResponseLegacy { private callback?: com.nativescript.https.OkHttpResponse.OkHttpResponseAsyncCallback; constructor(private response: com.nativescript.https.OkHttpResponse, private tag: string, private url: string) {} + get contentLength() { + return this.response.contentLength(); + } getOrCreateCloseCallback() { if (!notClosedResponses[this.tag]) { // we need to store handling request to be able to cancel them @@ -440,7 +443,11 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr const MEDIA_TYPE = okhttp3.MediaType.parse(param.contentType); builder.addFormDataPart(param.parameterName, param.fileName, okhttp3.RequestBody.create(MEDIA_TYPE, param.data)); } else { - builder.addFormDataPart(param.parameterName, param.data); + if (typeof param.data === 'string') { + builder.addFormDataPart(param.parameterName, param.data); + } else { + builder.addFormDataPart(param.parameterName, param.data + ''); + } } }); okHttpBody = builder.build(); @@ -520,7 +527,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr resolve({ response, - content: new HttpsResponseLegacyIOS(nResponse, tag, opts.url), + content: new HttpsResponseLegacy(nResponse, tag, opts.url), + contentLength: nResponse.contentLength(), statusCode, reason: message, get headers() { @@ -531,6 +539,7 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr resolve({ response, content: responseBody.string(), + contentLength: responseBody.contentLength(), reason: message, statusCode, get headers() { diff --git a/src/request.d.ts b/src/request.d.ts index 05f21ac..5af543b 100644 --- a/src/request.d.ts +++ b/src/request.d.ts @@ -62,6 +62,7 @@ export interface HttpsRequestOptions extends HttpRequestOptions { export interface HttpsResponse { headers?: Headers; statusCode?: number; + contentLength: number; content?: T; reason?: string; description?: string; @@ -76,6 +77,7 @@ export interface HttpsRequest { } export interface HttpsResponseLegacy { + contentLength: number; toArrayBuffer(): ArrayBuffer; toArrayBufferAsync(): Promise; diff --git a/src/request.ios.ts b/src/request.ios.ts index efdad2b..26b1f66 100644 --- a/src/request.ios.ts +++ b/src/request.ios.ts @@ -1,5 +1,5 @@ import { File, ImageSource, Utils } from '@nativescript/core'; -import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponse, HttpsResponseLegacy, HttpsSSLPinningOptions } from '.'; +import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponse, HttpsSSLPinningOptions, HttpsResponseLegacy as IHttpsResponseLegacy } from '.'; import { getFilenameFromUrl, parseJSON } from './request.common'; export { addInterceptor, addNetworkInterceptor } from './request.common'; @@ -90,9 +90,9 @@ function getData(data) { return content; } -class HttpsResponseLegacyAndroid implements HttpsResponseLegacy { +class HttpsResponseLegacy implements IHttpsResponseLegacy { // private callback?: com.nativescript.https.OkhttpResponse.OkHttpResponseAsyncCallback; - constructor(private data: NSDictionary & NSData & NSArray, private url: string) {} + constructor(private data: NSDictionary & NSData & NSArray, public contentLength, private url: string) {} toArrayBufferAsync(): Promise { throw new Error('Method not implemented.'); } @@ -230,6 +230,7 @@ function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError, let getHeaders = () => ({}); const sendi = ({ task, + contentLength: task.countOfBytesReceived, reason: error.localizedDescription, get headers() { return getHeaders(); @@ -265,11 +266,12 @@ function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError, failure.description = '@nativescript-community/https > Invalid SSL certificate! ' + error.description; } sendi.failure = failure; - sendi.content = new HttpsResponseLegacyAndroid(data, url); + sendi.content = new HttpsResponseLegacy(data, sendi.contentLength, url); resolve(sendi); } else { const content: any = { body: parsedData, + contentLength: sendi.contentLength, description: error.description, reason: error.localizedDescription, url: failingURL ? failingURL.description : url, @@ -379,10 +381,12 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr const success = function (task: NSURLSessionDataTask, data?: any) { clearRunningRequest(); // TODO: refactor this code with failure one. - const content = useLegacy ? new HttpsResponseLegacyAndroid(data, opts.url) : getData(data); + const contentLength = task.countOfBytesReceived; + const content = useLegacy ? new HttpsResponseLegacy(data, contentLength, opts.url) : getData(data); let getHeaders = () => ({}); const sendi = ({ content, + contentLength, get headers() { return getHeaders(); },