8000 feat: use `accept` header for signed URL (#150) · netlify/blobs@713e2be · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 713e2be

Browse files
feat: use accept header for signed URL (#150)
1 parent 3d0a386 commit 713e2be

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export class Client {
134134
}
135135
}
136136

137-
const res = await this.fetch(url.toString(), { headers: apiHeaders, method })
137+
const res = await this.fetch(url.toString(), {
138+
headers: { ...apiHeaders, accept: `application/json;type=signed-url` },
139+
method,
140+
})
138141

139142
if (res.status !== 200) {
140143
throw new Error(`Netlify Blobs has generated an internal error: ${res.status} response`)

src/main.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('get', () => {
4545
test('Reads from the blob store', async () => {
4646
const mockStore = new MockFetch()
4747
.get({
48-
headers: { authorization: `Bearer ${apiToken}` },
48+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
4949
response: new Response(JSON.stringify({ url: signedURL })),
5050
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
5151
})
@@ -54,7 +54,7 @@ describe('get', () => {
5454
url: signedURL,
5555
})
5656
.get({
57-
headers: { authorization: `Bearer ${apiToken}` },
57+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
5858
response: new Response(JSON.stringify({ url: signedURL })),
5959
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
6060
})
@@ -63,7 +63,7 @@ describe('get', () => {
6363
url: signedURL,
6464
})
6565
.get({
66-
headers: { authorization: `Bearer ${apiToken}` },
66+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
6767
response: new Response(JSON.stringify({ url: signedURL })),
6868
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${complexKey}`,
6969
})
@@ -95,7 +95,7 @@ describe('get', () => {
9595
test('Returns `null` when the pre-signed URL returns a 404', async () => {
9696
const mockStore = new MockFetch()
9797
.get({
98-
headers: { authorization: `Bearer ${apiToken}` },
98+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
9999
response: new Response(JSON.stringify({ url: signedURL })),
100100
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
101101
})
@@ -118,7 +118,7 @@ describe('get', () => {
118118

119119
test('Throws when the API returns a non-200 status code', async () => {
120120
const mockStore = new MockFetch().get({
121-
headers: { authorization: `Bearer ${apiToken}` },
121+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
122122
response: new Response(null, { status: 401 }),
123123
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
124124
})
@@ -140,7 +140,7 @@ describe('get', () => {
140140
test('Throws when a pre-signed URL returns a non-200 status code', async () => {
141141
const mockStore = new MockFetch()
142142
.get({
143-
headers: { authorization: `Bearer ${apiToken}` },
143+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
144144
response: new Response(JSON.stringify({ url: signedURL })),
145145
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
146146
})

0 commit comments

Comments
 (0)
0