Skip to content

Commit

Permalink
feat: use accept header for signed URL
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Mar 4, 2024
1 parent 3d0a386 commit 67cca9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ export class Client {
}
}

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

if (res.status !== 200) {
throw new Error(`Netlify Blobs has generated an internal error: ${res.status} response`)
Expand Down
12 changes: 6 additions & 6 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('get', () => {
test('Reads from the blob store', async () => {
const mockStore = new MockFetch()
.get({
headers: { authorization: `Bearer ${apiToken}` },
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
response: new Response(JSON.stringify({ url: signedURL })),
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
})
Expand All @@ -54,7 +54,7 @@ describe('get', () => {
url: signedURL,
})
.get({
headers: { authorization: `Bearer ${apiToken}` },
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
response: new Response(JSON.stringify({ url: signedURL })),
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
})
Expand All @@ -63,7 +63,7 @@ describe('get', () => {
url: signedURL,
})
.get({
headers: { authorization: `Bearer ${apiToken}` },
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
response: new Response(JSON.stringify({ url: signedURL })),
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${complexKey}`,
})
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('get', () => {
test('Returns `null` when the pre-signed URL returns a 404', async () => {
const mockStore = new MockFetch()
.get({
headers: { authorization: `Bearer ${apiToken}` },
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
response: new Response(JSON.stringify({ url: signedURL })),
url: `https://api.netlify.com/api/v1/blobs/${siteID}/site:production/${key}`,
})
Expand All @@ -118,7 +118,7 @@ describe('get', () => {

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

0 comments on commit 67cca9d

Please sign in to comment.