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:
|
||||
description: 'Content Type'
|
||||
required: false
|
||||
default: 'application/json'
|
||||
data:
|
||||
description: 'Request Body as JSON String'
|
||||
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 }) => {
|
||||
try {
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
if (escapeData) {
|
||||
data = data.replace(/"[^"]*"/g, (match) => {
|
||||
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||
|
@ -1375,6 +1373,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
|
|||
data
|
||||
}
|
||||
|
||||
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||
|
||||
const response = await instance.request(requestData)
|
||||
|
@ -1421,12 +1423,18 @@ const convertToFormData = (data, files) => {
|
|||
|
||||
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||
try {
|
||||
const formHeaders = formData.getHeaders()
|
||||
const contentType = formHeaders['content-type']
|
||||
|
||||
delete formHeaders['content-type']
|
||||
|
||||
return {
|
||||
...instanceConfig,
|
||||
headers: {
|
||||
...instanceConfig.headers,
|
||||
...formData.getHeaders(),
|
||||
'Content-Length': await contentLength(formData)
|
||||
...formHeaders,
|
||||
'Content-Length': await contentLength(formData),
|
||||
'Content-Type': contentType
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
|
@ -3561,8 +3569,6 @@ const instanceConfig = {
|
|||
headers: { ...headers, ...customHeaders }
|
||||
}
|
||||
|
||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
const data = core.getInput('data') || '{}';
|
||||
const files = core.getInput('files') || '{}';
|
||||
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 }) => {
|
||||
try {
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
if (escapeData) {
|
||||
data = data.replace(/"[^"]*"/g, (match) => {
|
||||
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||
|
@ -40,6 +38,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
|
|||
data
|
||||
}
|
||||
|
||||
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||
|
||||
const response = await instance.request(requestData)
|
||||
|
@ -86,12 +88,18 @@ const convertToFormData = (data, files) => {
|
|||
|
||||
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||
try {
|
||||
const formHeaders = formData.getHeaders()
|
||||
const contentType = formHeaders['content-type']
|
||||
|
||||
delete formHeaders['content-type']
|
||||
|
||||
return {
|
||||
...instanceConfig,
|
||||
headers: {
|
||||
...instanceConfig.headers,
|
||||
...formData.getHeaders(),
|
||||
'Content-Length': await contentLength(formData)
|
||||
...formHeaders,
|
||||
'Content-Length': await contentLength(formData),
|
||||
'Content-Type': contentType
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
|
|
|
@ -34,8 +34,6 @@ const instanceConfig = {
|
|||
headers: { ...headers, ...customHeaders }
|
||||
}
|
||||
|
||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
const data = core.getInput('data') || '{}';
|
||||
const files = core.getInput('files') || '{}';
|
||||
const method = core.getInput('method') || METHOD_POST;
|
||||
|
|
Loading…
Reference in a new issue