* Gets headers and values to attach to the web request. * @param {string} url - The url containing the headers and values to send. * @returns {object} An object specifying name and value of the headers.
(url)
| 150 | * @returns {object} An object specifying name and value of the headers. |
| 151 | */ |
| 152 | function getHeadersToSend (url) { |
| 153 | const headersToSend = { "User-Agent": getUserAgent() }; |
| 154 | const headersToSendMatch = new RegExp("sendheaders=(.+?)(&|$)", "g").exec(url); |
| 155 | if (headersToSendMatch) { |
| 156 | const headers = headersToSendMatch[1].split(","); |
| 157 | for (const header of headers) { |
| 158 | const keyValue = header.split(":"); |
| 159 | if (keyValue.length !== 2) { |
| 160 | throw new Error(`Invalid format for header ${header}`); |
| 161 | } |
| 162 | headersToSend[keyValue[0]] = decodeURIComponent(keyValue[1]); |
| 163 | } |
| 164 | } |
| 165 | return headersToSend; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Gets the headers expected from the response. |