(
url: string,
headers: Record<string, string>|null,
stream: Common.StringOutputStream.OutputStream,
callback?: ((arg0: boolean, arg1: Record<string, string>, arg2: LoadErrorDescription) => void),
allowRemoteFilePaths?: boolean,
)
| 214 | } |
| 215 | |
| 216 | export const loadAsStream = function( |
| 217 | url: string, |
| 218 | headers: Record<string, string>|null, |
| 219 | stream: Common.StringOutputStream.OutputStream, |
| 220 | callback?: ((arg0: boolean, arg1: Record<string, string>, arg2: LoadErrorDescription) => void), |
| 221 | allowRemoteFilePaths?: boolean, |
| 222 | ): void { |
| 223 | const streamId = bindOutputStream(stream); |
| 224 | const parsedURL = new Common.ParsedURL.ParsedURL(url); |
| 225 | if (parsedURL.isDataURL()) { |
| 226 | fetchToString(url).then(dataURLDecodeSuccessful).catch(dataURLDecodeFailed); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | if (!allowRemoteFilePaths && canBeRemoteFilePath(url)) { |
| 231 | // Remote file paths can cause security problems, see crbug.com/1342722. |
| 232 | if (callback) { |
| 233 | callback(/* success */ false, /* headers */ {}, { |
| 234 | statusCode: 400, // BAD_REQUEST |
| 235 | netError: -20, // BLOCKED_BY_CLIENT |
| 236 | netErrorName: 'net::BLOCKED_BY_CLIENT', |
| 237 | message: 'Loading from a remote file path is prohibited for security reasons.', |
| 238 | }); |
| 239 | } |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | const rawHeaders = []; |
| 244 | if (headers) { |
| 245 | for (const key in headers) { |
| 246 | rawHeaders.push(key + ': ' + headers[key]); |
| 247 | } |
| 248 | } |
| 249 | InspectorFrontendHostInstance.loadNetworkResource(url, rawHeaders.join('\r\n'), streamId, finishedCallback); |
| 250 | |
| 251 | function finishedCallback(response: LoadNetworkResourceResult): void { |
| 252 | if (callback) { |
| 253 | const {success, description} = createErrorMessageFromResponse(response); |
| 254 | callback(success, response.headers || {}, description); |
| 255 | } |
| 256 | discardOutputStream(streamId); |
| 257 | } |
| 258 | |
| 259 | function dataURLDecodeSuccessful(text: string): void { |
| 260 | streamWrite(streamId, text); |
| 261 | finishedCallback(({statusCode: 200})); |
| 262 | } |
| 263 | |
| 264 | function dataURLDecodeFailed(_xhrStatus: Error): void { |
| 265 | const messageOverride: string = i18nString(UIStrings.decodingDataUrlFailed); |
| 266 | finishedCallback(({statusCode: 404, messageOverride})); |
| 267 | } |
| 268 | }; |
no test coverage detected