MCPcopy
hub / github.com/MagicMirrorOrg/MagicMirror / getHeadersToSend

Function getHeadersToSend

js/server_functions.js:152–166  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

150 * @returns {object} An object specifying name and value of the headers.
151 */
152function 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.

Callers 1

corsFunction · 0.85

Calls 1

getUserAgentFunction · 0.85

Tested by

no test coverage detected