Skip to content

Commit b09da7f

Browse files
committed
fix(android): crash on response headers
1 parent e7a3f08 commit b09da7f

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/request.android.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,16 +496,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
496496
const message = OkHttpResponse.getMessage(response);
497497
const statusCode = OkHttpResponse.getStatusCode(response);
498498
const getHeaders = function () {
499-
const heads = response.headers();
500-
const headers = {};
501-
// let heads: okhttp3.Headers = resp.headers();
502-
const len: number = heads.size();
503-
let i: number;
504-
for (i = 0; i < len; i++) {
505-
const key = heads.name(i);
506-
headers[key] = heads.value(i);
507-
}
508-
return headers;
499+
const heads = OkHttpResponse.getHeaders(response);
500+
return JSON.parse(heads);
509501
};
510502
if (useLegacy) {
511503
const nResponse = new OkHttpResponse(responseBody);

src/typings/android.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ declare namespace com {
2323
toFileAsync(filePath: string, callback: OkHttpResponse.OkHttpResponseAsyncCallback);
2424

2525
static getStatusCode(response: okhttp3.Response): number;
26-
static getMessage(response: okhttp3.Response): String;
26+
static getMessage(response: okhttp3.Response): string;
27+
static getHeaders(response: okhttp3.Response): string;
2728
}
2829
export class ProgressRequestWrapper extends okhttp3.RequestBody {
2930
constructor(body: okhttp3.RequestBody, listener: ProgressRequestWrapper.ProgressListener);

0 commit comments

Comments
 (0)