Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readBodyBuffer method to HttpClientResponse #1475

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions packages/artifact/__tests__/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ describe('Download Tests', () => {
*/
async function emptyMockReadBody(): Promise<string> {
return new Promise(resolve => {
resolve()
resolve('')
})
}
async function emptyMockReadBodyBuffer(): Promise<Buffer> {
return new Promise(resolve => {
resolve(Buffer.alloc(0))
})
}

Expand Down Expand Up @@ -285,7 +290,8 @@ describe('Download Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: mockReadBody
readBody: mockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand Down Expand Up @@ -319,7 +325,8 @@ describe('Download Tests', () => {
fullResponse.length,
actualResponse
),
readBody: emptyMockReadBody
readBody: emptyMockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
}
} else {
return {
Expand All @@ -329,7 +336,8 @@ describe('Download Tests', () => {
0,
null
),
readBody: emptyMockReadBody
readBody: emptyMockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
}
}
})
Expand All @@ -346,7 +354,8 @@ describe('Download Tests', () => {
fullResponse.length,
fullResponse
),
readBody: emptyMockReadBody
readBody: emptyMockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
}
})
}
Expand Down Expand Up @@ -456,7 +465,8 @@ describe('Download Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: mockReadBody
readBody: mockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand All @@ -472,7 +482,8 @@ describe('Download Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: emptyMockReadBody
readBody: emptyMockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand Down
11 changes: 9 additions & 2 deletions packages/artifact/__tests__/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ beforeAll(async () => {
*/
async function emptyMockReadBody(): Promise<string> {
return new Promise(resolve => {
resolve()
resolve('')
})
}

async function emptyMockReadBodyBuffer(): Promise<Buffer> {
return new Promise(resolve => {
resolve(Buffer.alloc(0))
})
}

Expand All @@ -78,7 +84,8 @@ async function setupSingleMockResponse(
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: mockReadBody
readBody: mockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
}
Expand Down
17 changes: 13 additions & 4 deletions packages/artifact/__tests__/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,13 @@ describe('Upload Tests', () => {
*/
async function emptyMockReadBody(): Promise<string> {
return new Promise(resolve => {
resolve()
resolve('')
})
}

async function emptyMockReadBodyBuffer(): Promise<Buffer> {
return new Promise(resolve => {
resolve(Buffer.alloc(0))
})
}

Expand Down Expand Up @@ -475,7 +481,8 @@ describe('Upload Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: mockReadBody
readBody: mockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand All @@ -498,7 +505,8 @@ describe('Upload Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: emptyMockReadBody
readBody: emptyMockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand Down Expand Up @@ -543,7 +551,8 @@ describe('Upload Tests', () => {
return new Promise<HttpClientResponse>(resolve => {
resolve({
message: mockMessage,
readBody: mockReadBody
readBody: mockReadBody,
readBodyBuffer: emptyMockReadBodyBuffer
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/http-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/http-client",
"version": "2.1.0",
"version": "2.1.1",
"description": "Actions Http Client",
"keywords": [
"github",
Expand Down
14 changes: 14 additions & 0 deletions packages/http-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ export class HttpClientResponse {
})
})
}

async readBodyBuffer(): Promise<Buffer> {
return new Promise<Buffer>(async resolve => {
const chunks: Buffer[] = []

this.message.on('data', (chunk: Buffer) => {
chunks.push(chunk)
})

this.message.on('end', () => {
resolve(Buffer.concat(chunks))
})
})
}
}

export function isHttps(requestUrl: string): boolean {
Expand Down