mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-22 03:41:00 -05:00
Update FileUpload ContentType
This commit is contained in:
parent
b6bb4fa030
commit
42677b964e
4 changed files with 24 additions and 13 deletions
|
@ -11,7 +11,6 @@ inputs:
|
||||||
contentType:
|
contentType:
|
||||||
description: 'Content Type'
|
description: 'Content Type'
|
||||||
required: false
|
required: false
|
||||||
default: 'application/json'
|
|
||||||
data:
|
data:
|
||||||
description: 'Request Body as JSON String'
|
description: 'Request Body as JSON String'
|
||||||
required: false
|
required: false
|
||||||
|
|
18
dist/index.js
vendored
18
dist/index.js
vendored
|
@ -1342,8 +1342,6 @@ const METHOD_POST = 'POST'
|
||||||
|
|
||||||
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
||||||
try {
|
try {
|
||||||
const instance = axios.create(instanceConfig);
|
|
||||||
|
|
||||||
if (escapeData) {
|
if (escapeData) {
|
||||||
data = data.replace(/"[^"]*"/g, (match) => {
|
data = data.replace(/"[^"]*"/g, (match) => {
|
||||||
return match.replace(/[\n\r]\s*/g, "\\n");
|
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||||
|
@ -1375,6 +1373,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||||
|
|
||||||
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||||
|
|
||||||
const response = await instance.request(requestData)
|
const response = await instance.request(requestData)
|
||||||
|
@ -1421,12 +1423,18 @@ const convertToFormData = (data, files) => {
|
||||||
|
|
||||||
const updateConfig = async (instanceConfig, formData, actions) => {
|
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||||
try {
|
try {
|
||||||
|
const formHeaders = formData.getHeaders()
|
||||||
|
const contentType = formHeaders['content-type']
|
||||||
|
|
||||||
|
delete formHeaders['content-type']
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...instanceConfig,
|
...instanceConfig,
|
||||||
headers: {
|
headers: {
|
||||||
...instanceConfig.headers,
|
...instanceConfig.headers,
|
||||||
...formData.getHeaders(),
|
...formHeaders,
|
||||||
'Content-Length': await contentLength(formData)
|
'Content-Length': await contentLength(formData),
|
||||||
|
'Content-Type': contentType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
@ -3561,8 +3569,6 @@ const instanceConfig = {
|
||||||
headers: { ...headers, ...customHeaders }
|
headers: { ...headers, ...customHeaders }
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
|
||||||
|
|
||||||
const data = core.getInput('data') || '{}';
|
const data = core.getInput('data') || '{}';
|
||||||
const files = core.getInput('files') || '{}';
|
const files = core.getInput('files') || '{}';
|
||||||
const method = core.getInput('method') || METHOD_POST;
|
const method = core.getInput('method') || METHOD_POST;
|
||||||
|
|
|
@ -7,8 +7,6 @@ const METHOD_POST = 'POST'
|
||||||
|
|
||||||
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
||||||
try {
|
try {
|
||||||
const instance = axios.create(instanceConfig);
|
|
||||||
|
|
||||||
if (escapeData) {
|
if (escapeData) {
|
||||||
data = data.replace(/"[^"]*"/g, (match) => {
|
data = data.replace(/"[^"]*"/g, (match) => {
|
||||||
return match.replace(/[\n\r]\s*/g, "\\n");
|
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||||
|
@ -40,6 +38,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||||
|
|
||||||
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||||
|
|
||||||
const response = await instance.request(requestData)
|
const response = await instance.request(requestData)
|
||||||
|
@ -86,12 +88,18 @@ const convertToFormData = (data, files) => {
|
||||||
|
|
||||||
const updateConfig = async (instanceConfig, formData, actions) => {
|
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||||
try {
|
try {
|
||||||
|
const formHeaders = formData.getHeaders()
|
||||||
|
const contentType = formHeaders['content-type']
|
||||||
|
|
||||||
|
delete formHeaders['content-type']
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...instanceConfig,
|
...instanceConfig,
|
||||||
headers: {
|
headers: {
|
||||||
...instanceConfig.headers,
|
...instanceConfig.headers,
|
||||||
...formData.getHeaders(),
|
...formHeaders,
|
||||||
'Content-Length': await contentLength(formData)
|
'Content-Length': await contentLength(formData),
|
||||||
|
'Content-Type': contentType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
|
|
@ -34,8 +34,6 @@ const instanceConfig = {
|
||||||
headers: { ...headers, ...customHeaders }
|
headers: { ...headers, ...customHeaders }
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
|
||||||
|
|
||||||
const data = core.getInput('data') || '{}';
|
const data = core.getInput('data') || '{}';
|
||||||
const files = core.getInput('files') || '{}';
|
const files = core.getInput('files') || '{}';
|
||||||
const method = core.getInput('method') || METHOD_POST;
|
const method = core.getInput('method') || METHOD_POST;
|
||||||
|
|
Loading…
Reference in a new issue