@@ -3,28 +3,33 @@ const axios = require('axios');
33// TODO: figure out how to get JSDocs to work properly
44/**
55 * Generate a simple request object
6- * @typedef {Object } Request
6+ * @typedef {object } Request
77 * @param {string } url The URL
88 * @param {string } method The HTTP method to use (defaults to GET)
99 * @param {string } [body] Optional HTML markup or plaintext to pass as POST body
10- * @param {Object } headers The request headers
10+ * @param {object } headers The request headers
1111 */
1212
1313/**
1414 * Generate a simple request object
1515 * @param {string } url The URL
1616 * @param {string } [method] The HTTP method to use (defaults to GET)
1717 * @param {string } [body] Optional HTML markup or plaintext to pass as POST body
18- * @param {Object } [customHeaders] Optional additional request headers object
18+ * @param {object } [customHeaders] Optional additional request headers object
1919 * @returns {Request } The request object
2020 */
2121exports . generate = function ( url , method = 'GET' , body , customHeaders ) {
22- let headers = { ...customHeaders } ;
22+ // Add 'X-Forward-' to all the custom headers
23+ const headers = Object . entries ( { ...customHeaders } ) . reduce ( ( acc , [ key , value ] ) => {
24+ acc [ 'X-Forward-' + key ] = value ;
25+ return acc ;
26+ } , { } ) ;
27+
2328 if ( body ) {
2429 if ( body . startsWith ( '<' ) )
25- headers = { 'Content-Type' : 'text/html' } ;
30+ headers [ 'Content-Type' ] = 'text/html' ;
2631 else
27- headers = { 'Content-Type' : 'text/plain' } ;
32+ headers [ 'Content-Type' ] = 'text/plain' ;
2833 }
2934
3035 return {
0 commit comments