diff --git a/bin/smee.js b/bin/smee.js index bda21468..df4d2b1f 100755 --- a/bin/smee.js +++ b/bin/smee.js @@ -21,6 +21,7 @@ program ) .option("-p, --port ", "Local HTTP server port", process.env.PORT || 3000) .option("-P, --path ", "URL path to post proxied requests to`", "/") + .option("-h, --deleteHeaders ", "List of headers to remove from request, comma separated", "") .parse(process.argv); const opts = program.opts(); @@ -29,12 +30,17 @@ const { target = `http://127.0.0.1:${opts.port}${opts.path}` } = opts; async function setup() { let source = opts.url; + let headersToDelete; + + if(opts.deleteHeaders){ + headersToDelete = opts.deleteHeaders.split(","); + } if (!source) { source = await Client.createChannel(); } - const client = new Client({ source, target }); + const client = new Client({ source, target, deleteHeaders: headersToDelete}); client.start(); } diff --git a/index.ts b/index.ts index a418b22e..dac16076 100644 --- a/index.ts +++ b/index.ts @@ -16,6 +16,7 @@ interface Options { target: string; logger?: Pick; fetch?: any; + deleteHeaders?: Array; } const proxyAgent = new EnvHttpProxyAgent(); @@ -24,19 +25,24 @@ class Client { #source: string; #target: string; #fetch: typeof undiciFetch; + #deleteHeaders: Array; + #logger: Pick; #events!: EventSource; + constructor({ source, target, logger = console, fetch = undiciFetch, + deleteHeaders = [] }: Options) { this.#source = source; this.#target = target; this.#logger = logger!; this.#fetch = fetch; + this.#deleteHeaders = deleteHeaders; if (!validator.isURL(this.#source)) { throw new Error("The provided URL is invalid."); @@ -78,6 +84,7 @@ class Client { // See https://github.com/probot/smee-client/issues/295 // See https://github.com/probot/smee-client/issues/187 delete headers["host"]; + this.#deleteHeaders.forEach((header) => delete headers[header]); headers["content-length"] = Buffer.byteLength(body); headers["content-type"] = "application/json";