Skip to content

Commit

Permalink
[Feature] Allow to override request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kHorozhanov committed Apr 10, 2023
1 parent f28bb48 commit 42eecce
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
15 changes: 11 additions & 4 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ if (queryParamsString) {
const body = events.length
? events.map(objectToQueryString).join('\n')
: undefined;
const headers = {
'Content-Type': 'text/plain;charset=UTF-8',
'User-Agent': userAgent,
};

if (data.requestHeaders && data.requestHeaders.length) {
data.requestHeaders.forEach((header) => {
headers[header.name] = header.value;
});
}

if (isLoggingEnabled) {
logToConsole(
Expand All @@ -91,10 +101,7 @@ if (isLoggingEnabled) {
sendHttpRequest(
postUrl,
{
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
'User-Agent': userAgent,
},
headers: headers,
method: 'POST',
},
body
Expand Down
54 changes: 50 additions & 4 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,45 @@ ___TEMPLATE_PARAMETERS___
}
]
},
{
"type": "GROUP",
"name": "requestHeadersGroup",
"displayName": "Request Headers",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "PARAM_TABLE",
"name": "requestHeaders",
"displayName": "",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "name",
"displayName": "Name",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "value",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
}
],
"newRowButtonText": "+ Add header"
}
]
},
{
"type": "GROUP",
"name": "dataSourceGroup",
Expand Down Expand Up @@ -361,6 +400,16 @@ if (queryParamsString) {
const body = events.length
? events.map(objectToQueryString).join('\n')
: undefined;
const headers = {
'Content-Type': 'text/plain;charset=UTF-8',
'User-Agent': userAgent,
};

if (data.requestHeaders && data.requestHeaders.length) {
data.requestHeaders.forEach((header) => {
headers[header.name] = header.value;
});
}

if (isLoggingEnabled) {
logToConsole(
Expand All @@ -376,10 +425,7 @@ if (isLoggingEnabled) {
sendHttpRequest(
postUrl,
{
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
'User-Agent': userAgent,
},
headers: headers,
method: 'POST',
},
body
Expand Down

0 comments on commit 42eecce

Please sign in to comment.