* @param {GMReq.Message.BG} msg * @returns {Promise }
(msg)
| 105 | * @returns {Promise<void>} |
| 106 | */ |
| 107 | async HttpRequested(msg) { |
| 108 | const { id, data } = msg; |
| 109 | const req = requests[id]; |
| 110 | if (!req) { |
| 111 | if (process.env.DEV) console.warn('[HttpRequested][content]: no request for id', id); |
| 112 | return; |
| 113 | } |
| 114 | if (hasOwnProperty(msg, 'chunk')) { |
| 115 | processChunk(req, data, msg); |
| 116 | return; |
| 117 | } |
| 118 | let response = data?.[kResponse]; |
| 119 | if (response != null) { |
| 120 | if (msg.blobbed) { |
| 121 | response = await importBlob(response, isBlobXhr(req)); |
| 122 | sendCmd('RevokeBlob', response); |
| 123 | } else if (msg.chunked) { |
| 124 | processChunk(req, response); |
| 125 | response = req[CHUNKS]; |
| 126 | delete req[CHUNKS]; |
| 127 | if (isBlobXhr(req)) { |
| 128 | response = makeSafeBlob(response, msg.contentType); |
| 129 | } else if (req[kXhrType]) { |
| 130 | response = response::getTypedArrayBuffer(); |
| 131 | } else { |
| 132 | // sending text chunks as-is to avoid memory overflow due to concatenation |
| 133 | } |
| 134 | } |
| 135 | data[kResponse] = response; |
| 136 | } |
| 137 | if (msg.type === LOADEND && !msg[UPLOAD]) { |
| 138 | delete requests[msg.id]; |
| 139 | } |
| 140 | sendHttpRequested(msg, req.realm); |
| 141 | }, |
| 142 | }); |
| 143 | |
| 144 | /** |
nothing calls this directly
no test coverage detected