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

feat: use accept header for signed URL #150

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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