From 4cbc7a46b206a7aad09ef774775110b7b94f8523 Mon Sep 17 00:00:00 2001 From: Nick Hills Date: Wed, 17 Aug 2022 08:56:02 +0100 Subject: [PATCH] Adding ability to return headers without setting debug mode (#51) * Update httpClient.js * Update README.md * Update action.yml Co-authored-by: Nick Hills --- README.md | 2 ++ action.yml | 2 ++ dist/index.js | 2 ++ src/httpClient.js | 2 ++ 4 files changed, 8 insertions(+) diff --git a/README.md b/README.md index f7c667a..4b6255e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ jobs: | Variable | Description | |---|---| `response` | Response as JSON String +`headers` | Headers To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`. You can also access specific field from the response data using [fromJson()](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson) expression. @@ -61,6 +62,7 @@ steps: - name: Show Response run: | echo ${{ steps.myRequest.outputs.response }} + echo ${{ steps.myRequest.outputs.headers }} echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }} ``` diff --git a/action.yml b/action.yml index b200959..5bed675 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,8 @@ inputs: outputs: response: description: 'HTTP Response Content' + headers: + description: 'HTTP Response Headers' runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 9c479b4..29f8d3c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1968,6 +1968,8 @@ const request = async({ method, instanceConfig, data, files, file, actions, igno const response = await instance.request(requestData) actions.setOutput('response', JSON.stringify(response.data)) + + actions.setOutput('headers', response.headers) } catch (error) { if ((typeof error === 'object') && (error.isAxiosError === true)) { const { name, message, code, response } = error diff --git a/src/httpClient.js b/src/httpClient.js index 9eedc88..6823afc 100644 --- a/src/httpClient.js +++ b/src/httpClient.js @@ -68,6 +68,8 @@ const request = async({ method, instanceConfig, data, files, file, actions, igno const response = await instance.request(requestData) actions.setOutput('response', JSON.stringify(response.data)) + + actions.setOutput('headers', response.headers) } catch (error) { if ((typeof error === 'object') && (error.isAxiosError === true)) { const { name, message, code, response } = error