Skip to content

Commit

Permalink
feat(http): add configurable deny-list of headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSelene committed Oct 15, 2024
1 parent dd6107d commit 748beb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/http/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@activepieces/piece-http",
"version": "0.5.1"
"version": "0.5.2"
}

5 changes: 5 additions & 0 deletions packages/pieces/community/http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ export const http = createPiece({
],
triggers: [],
});


export type HttpPieceConfig = {
deniedHeaders?: string[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import FormData from 'form-data';
import { httpMethodDropdown } from '../common/props';
import { HttpsProxyAgent } from 'https-proxy-agent';
import axios from 'axios';
import { HttpPieceConfig } from '../../index';

export const httpSendRequestAction = createAction({
name: 'send_request',
Expand Down Expand Up @@ -163,6 +164,18 @@ export const httpSendRequestAction = createAction({
assertNotNullOrUndefined(method, 'Method');
assertNotNullOrUndefined(url, 'URL');

const pieceConfig = context.pieceConfig as HttpPieceConfig;
const deniedHeaders =
pieceConfig.deniedHeaders?.map((header) => header.toLowerCase().trim()) ||
[];
const blockedHeaders = Object.keys(headers).filter(
(headerName) => deniedHeaders.includes(headerName.toLowerCase().trim())
);

if (blockedHeaders.length > 0) {
throw new Error(`These headers are not allowed: ${blockedHeaders}`);
}

const request: HttpRequest = {
method,
url,
Expand Down Expand Up @@ -198,7 +211,7 @@ export const httpSendRequestAction = createAction({
proxyUrl = `http://${proxySettings.proxy_host}:${proxySettings.proxy_port}`;
}

const httpsAgent = new HttpsProxyAgent(proxyUrl)
const httpsAgent = new HttpsProxyAgent(proxyUrl);
const axiosClient = axios.create({
httpsAgent,
});
Expand Down

0 comments on commit 748beb0

Please sign in to comment.