@@ -65,6 +65,25 @@ function parseJSON(source: string): any {
65
65
return JSON . parse ( src ) ;
66
66
}
67
67
68
+ const textTypes : string [ ] = [
69
+ 'text/plain' ,
70
+ 'application/xml' ,
71
+ 'application/rss+xml' ,
72
+ 'text/html' ,
73
+ 'text/xml'
74
+ ] ;
75
+
76
+ const isTextContentType = ( contentType : string ) : boolean => {
77
+ let result = false ;
78
+ for ( let i = 0 ; i < textTypes . length ; i ++ ) {
79
+ if ( contentType . toLowerCase ( ) . indexOf ( textTypes [ i ] ) >= 0 ) {
80
+ result = true ;
81
+ break ;
82
+ }
83
+ }
84
+ return result ;
85
+ } ;
86
+
68
87
const requestCallbacks = new Map ( ) ;
69
88
let requestIdCounter = 0 ;
70
89
@@ -146,12 +165,35 @@ export class Http {
146
165
} ,
147
166
onComplete ( result : any ) : void {
148
167
let content ;
168
+ let responseText ;
149
169
let isString = false ;
150
170
if ( result . content instanceof org . json . JSONObject || result . content instanceof org . json . JSONArray ) {
151
171
content = deserialize ( result . content ) ;
172
+ try {
173
+ responseText = JSON . stringify ( content ) ;
174
+ } catch ( err ) {
175
+ this . _reject ( {
176
+ type : HttpError . Error ,
177
+ ios : null ,
178
+ message : err
179
+ } ) ;
180
+ return ;
181
+ }
152
182
isString = true ;
153
183
} else {
154
184
content = result . content ;
185
+ if ( content instanceof java . lang . String || typeof content === 'string' ) {
186
+ try {
187
+ responseText = JSON . stringify ( content ) ;
188
+ } catch ( err ) {
189
+ this . _reject ( {
190
+ type : HttpError . Error ,
191
+ ios : null ,
192
+ message : err
193
+ } ) ;
194
+ return ;
195
+ }
196
+ }
155
197
}
156
198
if ( result && result . headers ) {
157
199
const length = result . headers . size ( ) ;
@@ -207,14 +249,27 @@ export class Http {
207
249
url : result . url ,
208
250
statusCode,
209
251
headers,
210
- responseAsString : isString ? result . content . toString ( ) : null ,
252
+ responseAsString : isString ? result . content . toString ( ) : null ,
211
253
responseAsImage : null // TODO needs base64 Image
212
254
} , headers ) ;
213
255
}
214
256
257
+ if ( isTextContentType ( returnType ) && ! responseText ) {
258
+ try {
259
+ responseText = JSON . stringify ( content ) ;
260
+ } catch ( err ) {
261
+ this . _reject ( {
262
+ type : HttpError . Error ,
263
+ ios : null ,
264
+ message : err
265
+ } ) ;
266
+ return ;
267
+ }
268
+ }
215
269
resolve ( {
216
270
url : result . url ,
217
271
content,
272
+ responseText,
218
273
statusCode : statusCode ,
219
274
headers : headers
220
275
} ) ;
0 commit comments