1- import { File , HttpResponseEncoding , ImageSource , Utils } from '@nativescript/core' ;
1+ import { File , ImageSource } from '@nativescript/core' ;
22import { CacheOptions , HttpsFormDataParam , HttpsRequest , HttpsRequestOptions , HttpsSSLPinningOptions , HttpsResponseLegacy as IHttpsResponseLegacy } from '.' ;
33
4- import { getFilenameFromUrl , interceptors , networkInterceptors , parseJSON } from './request.common' ;
5- export { addNetworkInterceptor , addInterceptor } from './request.common' ;
4+ import { HttpResponseEncoding , getFilenameFromUrl , interceptors , networkInterceptors , parseJSON } from './request.common' ;
5+ export { HttpResponseEncoding , addInterceptor , addNetworkInterceptor } from './request.common' ;
66
77interface Ipeer {
88 enabled : boolean ;
@@ -123,36 +123,36 @@ class HttpsResponseLegacy implements IHttpsResponseLegacy {
123123
124124 // cache it because asking it again wont work as the socket is closed
125125 stringResponse : string ;
126- toString ( encoding ?: string ) {
126+ toString ( encoding ?: HttpResponseEncoding ) {
127127 // TODO: handle arraybuffer already stored
128- this . stringResponse = this . stringResponse || this . response . asString ( ) ;
128+ this . stringResponse = this . stringResponse || this . response . asString ( encoding ) ;
129129 return this . stringResponse ;
130130 }
131- async toStringAsync ( encoding ?: string ) : Promise < string > {
131+ async toStringAsync ( encoding ?: HttpResponseEncoding ) : Promise < string > {
132132 if ( this . stringResponse ) {
133133 return this . stringResponse ;
134134 }
135135 // TODO: handle arraybuffer already stored
136136 this . stringResponse = await new Promise < string > ( ( resolve , reject ) => {
137137 this . getOrCreateCloseCallback ( ) ;
138- this . response . asStringAsync ( this . getCallback ( resolve , reject ) ) ;
138+ this . response . asStringAsync ( encoding , this . getCallback ( resolve , reject ) ) ;
139139 } ) ;
140140 return this . stringResponse ;
141141 }
142142
143143 // cache it because asking it again wont work as the socket is closed
144144 jsonResponse : any ;
145- toJSON ( encoding ?: string ) {
145+ toJSON ( encoding ?: HttpResponseEncoding ) {
146146 if ( this . jsonResponse !== undefined ) {
147147 return this . jsonResponse ;
148148 }
149149 // TODO: handle arraybuffer already stored
150- this . stringResponse = this . stringResponse || this . response . asString ( ) ;
150+ this . stringResponse = this . stringResponse || this . response . asString ( encoding ) ;
151151 this . jsonResponse = this . stringResponse ? parseJSON ( this . stringResponse ) : null ;
152152 return this . jsonResponse ;
153153 }
154154
155- async toJSONAsync < T > ( ) {
155+ async toJSONAsync < T > ( encoding ?: HttpResponseEncoding ) {
156156 if ( this . jsonResponse !== undefined ) {
157157 return this . jsonResponse ;
158158 }
@@ -161,7 +161,7 @@ class HttpsResponseLegacy implements IHttpsResponseLegacy {
161161 return this . jsonResponse ;
162162 }
163163 // TODO: handle arraybuffer already stored
164- const r = await this . toStringAsync ( ) ;
164+ const r = await this . toStringAsync ( encoding ) ;
165165 this . jsonResponse = r ? parseJSON ( r ) : null ;
166166 return this . jsonResponse as T ;
167167 }
@@ -248,6 +248,19 @@ const SDKVersion = android.os.Build.VERSION.SDK_INT;
248248let Client : okhttp3 . OkHttpClient ;
249249let cookieJar : com . nativescript . https . QuotePreservingCookieJar ;
250250let cookieManager : java . net . CookieManager ;
251+
252+ export function getCookie ( key : string ) {
253+ const cookies = cookieManager ?. getCookieStore ( ) ?. getCookies ( ) ;
254+ if ( cookies ) {
255+ for ( let index = 0 ; index < cookies . size ( ) ; index ++ ) {
256+ const cookie = cookies . get ( index ) as java . net . HttpCookie ;
257+ const name = cookie . getName ( ) ;
258+ if ( name === key ) {
259+ return cookie . getValue ( ) ;
260+ }
261+ }
262+ }
263+ }
251264export function getClient ( opts : Partial < HttpsRequestOptions > = { } , reload : boolean = false ) : okhttp3 . OkHttpClient {
252265 if ( ! Client ) {
253266 // ssl error fix on KitKat. Only need to be done once.
0 commit comments