@param {GMReq.Message.BG} msg
(msg)
| 53 | addHandlers({ |
| 54 | /** @param {GMReq.Message.BG} msg */ |
| 55 | HttpRequested(msg) { |
| 56 | const req = idMap[msg.id]; |
| 57 | if (!req) { |
| 58 | return; |
| 59 | } |
| 60 | const { type } = msg; |
| 61 | const upload = getOwnProp(msg, UPLOAD); |
| 62 | const cb = req.cb[upload ? 1 : 0][type]; |
| 63 | if (!upload && type === 'loadend') { |
| 64 | delete idMap[req.id]; |
| 65 | } |
| 66 | if (hasOwnProperty(msg, ERROR)) { |
| 67 | msg = msg[ERROR]; |
| 68 | msg = new SafeDOMException(msg[0], msg[1]); |
| 69 | if (cb) cb(msg); else log(ERROR, displayNames[req.scriptId], msg); |
| 70 | return; |
| 71 | } |
| 72 | if (!cb) { |
| 73 | return; |
| 74 | } |
| 75 | const { data } = msg; |
| 76 | const { |
| 77 | [kResponse]: response, |
| 78 | [kResponseHeaders]: headers, |
| 79 | } = data; |
| 80 | let raw = req[kRaw]; |
| 81 | if (response != null) { |
| 82 | if (req[kXhrType]) { |
| 83 | req[kRaw] = response; |
| 84 | } else { |
| 85 | if (!raw) raw = req[kRaw] = []; |
| 86 | if (isString(response)) { |
| 87 | safePush(raw, response); |
| 88 | } else { |
| 89 | for (const chunk of response) safePush(raw, chunk); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | if (req[kXhrType]) { |
| 94 | setOwnProp(data, kResponseText, null); |
| 95 | } else if (!raw || raw.length <= 1) { |
| 96 | setOwnProp(data, kResponseText, raw && raw[0] || ''); |
| 97 | } else if (raw.length) { |
| 98 | setOwnProp(data, kResponseText, safeBind(parseRaw, data, req, msg, kResponseText), |
| 99 | true, 'get'); |
| 100 | } |
| 101 | if (headers != null) { |
| 102 | req[kResponseHeaders] = headers; |
| 103 | } |
| 104 | setOwnProp(data, 'context', req.context); |
| 105 | setOwnProp(data, kResponseHeaders, req[kResponseHeaders]); |
| 106 | setOwnProp(data, kResponseXML, safeBind(parseRaw, data, req, msg, kResponseXML), true, 'get'); |
| 107 | setOwnProp(data, kResponse, safeBind(parseRaw, data, req, msg, kResponse), true, 'get'); |
| 108 | cb(data); |
| 109 | }, |
| 110 | }); |
| 111 | |
| 112 | /** |
nothing calls this directly
no test coverage detected