mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-22 11:51:03 -05:00
Add support for custom headers
This commit is contained in:
parent
df0f4b3bfd
commit
0170dcbc31
2 changed files with 12 additions and 1 deletions
|
@ -27,6 +27,7 @@ jobs:
|
||||||
|username| Username for Basic Auth ||
|
|username| Username for Basic Auth ||
|
||||||
|password| Password for Basic Auth ||
|
|password| Password for Basic Auth ||
|
||||||
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|
||||||
|
|customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'|
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
|
|
||||||
|
|
12
src/index.js
12
src/index.js
|
@ -2,6 +2,16 @@ const core = require("@actions/core");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
|
||||||
const auth = {}
|
const auth = {}
|
||||||
|
let customHeaders = {}
|
||||||
|
|
||||||
|
if (!!core.getInput('customHeaders')) {
|
||||||
|
try {
|
||||||
|
customHeaders = JSON.parse(core.getInput('customHeaders'));
|
||||||
|
} catch(error) {
|
||||||
|
core.error('Could not parse customHeaders string value')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
||||||
|
|
||||||
if (!!core.getInput('username')) {
|
if (!!core.getInput('username')) {
|
||||||
|
@ -19,7 +29,7 @@ if (!!core.getInput('bearerToken')) {
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: core.getInput('url', { required: true }),
|
baseURL: core.getInput('url', { required: true }),
|
||||||
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||||
headers
|
headers: { ...headers, ...customHeaders }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue