(requestId: number, result: org.nativescript.widgets.Async.Http.RequestResult, headers: any)
| 116 | } |
| 117 | |
| 118 | export function responseReceived(requestId: number, result: org.nativescript.widgets.Async.Http.RequestResult, headers: any) { |
| 119 | const requestIdStr = requestId.toString(); |
| 120 | // Content-Type and content-type are both common in headers spelling |
| 121 | const mimeType: string = <string>headers['Content-Type'] || <string>headers['content-type'] || 'application/octet-stream'; |
| 122 | const contentLengthHeader: string = <string>headers['Content-Length'] || <string>headers['content-length']; |
| 123 | let contentLength = parseInt(contentLengthHeader, 10); |
| 124 | if (isNaN(contentLength)) { |
| 125 | contentLength = 0; |
| 126 | } |
| 127 | |
| 128 | const response: NetworkAgent.Response = { |
| 129 | url: result.url || '', |
| 130 | status: result.statusCode, |
| 131 | statusText: result.statusText || '', |
| 132 | headers: headers, |
| 133 | mimeType: mimeType, |
| 134 | fromDiskCache: false, |
| 135 | connectionReused: true, |
| 136 | connectionId: 0, |
| 137 | encodedDataLength: contentLength, |
| 138 | securityState: 'info', |
| 139 | }; |
| 140 | |
| 141 | const responseData: NetworkAgent.ResponseData = { |
| 142 | requestId: requestIdStr, |
| 143 | type: mimeTypeToType(response.mimeType), |
| 144 | response: response, |
| 145 | timestamp: getTimeStamp(), |
| 146 | }; |
| 147 | |
| 148 | global.__inspector.responseReceived(responseData); |
| 149 | global.__inspector.loadingFinished({ |
| 150 | requestId: requestIdStr, |
| 151 | timestamp: getTimeStamp(), |
| 152 | encodedDataLength: contentLength, |
| 153 | }); |
| 154 | |
| 155 | const hasTextContent = responseData.type === 'Document' || responseData.type === 'Script'; |
| 156 | let data; |
| 157 | |
| 158 | if (!hasTextContent) { |
| 159 | if (responseData.type === 'Image') { |
| 160 | const bitmap = result.responseAsImage; |
| 161 | if (bitmap) { |
| 162 | const outputStream = new java.io.ByteArrayOutputStream(); |
| 163 | bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, outputStream); |
| 164 | |
| 165 | const base64Image = android.util.Base64.encodeToString(outputStream.toByteArray(), android.util.Base64.DEFAULT); |
| 166 | data = base64Image; |
| 167 | } |
| 168 | } |
| 169 | } else { |
| 170 | data = result.responseAsString; |
| 171 | } |
| 172 | |
| 173 | const successfulRequestData: NetworkAgent.SuccessfulRequestData = { |
| 174 | requestId: requestIdStr, |
| 175 | data: data, |
nothing calls this directly
no test coverage detected