artifact header cleanup (#441)

* Update NPM packages for @actions/artifact

* Clarifications around headers

* Revert NPM updates

* Apply suggestions from code review

Co-authored-by: Josh Gross <joshmgross@github.com>

Co-authored-by: Josh Gross <joshmgross@github.com>
This commit is contained in:
Konrad Pabjan
2020-05-12 17:48:36 +02:00
committed by GitHub
parent d1b52e7168
commit 0471ed4ad7
4 changed files with 47 additions and 52 deletions

View File

@@ -3,7 +3,7 @@ import * as core from '@actions/core'
import * as zlib from 'zlib'
import {
getArtifactUrl,
getDownloadRequestOptions,
getDownloadHeaders,
isSuccessStatusCode,
isRetryableStatusCode,
isThrottledStatusCode,
@@ -40,8 +40,8 @@ export class DownloadHttpClient {
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.downloadHttpManager.getClient(0)
const requestOptions = getDownloadRequestOptions('application/json')
const response = await client.get(artifactUrl, requestOptions)
const headers = getDownloadHeaders('application/json')
const response = await client.get(artifactUrl, headers)
const body: string = await response.readBody()
if (isSuccessStatusCode(response.message.statusCode) && body) {
@@ -68,8 +68,8 @@ export class DownloadHttpClient {
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.downloadHttpManager.getClient(0)
const requestOptions = getDownloadRequestOptions('application/json')
const response = await client.get(resourceUrl.toString(), requestOptions)
const headers = getDownloadHeaders('application/json')
const response = await client.get(resourceUrl.toString(), headers)
const body: string = await response.readBody()
if (isSuccessStatusCode(response.message.statusCode) && body) {
@@ -149,22 +149,19 @@ export class DownloadHttpClient {
let retryCount = 0
const retryLimit = getRetryLimit()
const destinationStream = fs.createWriteStream(downloadPath)
const requestOptions = getDownloadRequestOptions(
'application/json',
true,
true
)
const headers = getDownloadHeaders('application/json', true, true)
// a single GET request is used to download a file
const makeDownloadRequest = async (): Promise<IHttpClientResponse> => {
const client = this.downloadHttpManager.getClient(httpClientIndex)
return await client.get(artifactLocation, requestOptions)
return await client.get(artifactLocation, headers)
}
// check the response headers to determine if the file was compressed using gzip
const isGzip = (headers: IncomingHttpHeaders): boolean => {
const isGzip = (incomingHeaders: IncomingHttpHeaders): boolean => {
return (
'content-encoding' in headers && headers['content-encoding'] === 'gzip'
'content-encoding' in incomingHeaders &&
incomingHeaders['content-encoding'] === 'gzip'
)
}