Skip to content

Commit

Permalink
fix: casing now matches what comes in a Netlify function via event.he…
Browse files Browse the repository at this point in the history
…aders (#181)
  • Loading branch information
nickytonline authored Aug 10, 2023
1 parent d946c42 commit 978f4c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { loadSourceImage as defaultLoadSourceImage } from './http'
import { decodeBase64Params, doPatternsMatchUrl, RemotePattern } from './utils'

// WAF is Web Application Firewall
const WAF_BYPASS_TOKEN_HEADER = 'X-Nf-Waf-Bypass-Token'
const WAF_BYPASS_TOKEN_HEADER = 'x-nf-waf-bypass-token'

export interface IPXHandlerOptions extends Partial<IPXOptions> {
/**
Expand Down
10 changes: 5 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test('should add WAF headers to local images being transformed', async (t) => {
cacheDir: '/tmp/ipx-cache',
bypassDomainCheck: true
}, (sourceImageOptions) => {
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['X-Nf-Waf-Bypass-Token'] === 'some token')
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['x-nf-waf-bypass-token'] === 'some token')

return Promise.resolve({ finalize: () => { } } as SourceImageResult)
})
Expand All @@ -116,7 +116,7 @@ test('should add WAF headers to local images being transformed', async (t) => {
{
rawUrl: 'http://localhost:3000/some-path',
path: '/_ipx/w_500/no-file.jpg',
headers: { 'X-Nf-Waf-Bypass-Token': 'some token' },
headers: { 'x-nf-waf-bypass-token': 'some token' },
rawQuery: '',
httpMethod: 'GET',
queryStringParameters: {},
Expand All @@ -135,7 +135,7 @@ test('should not add WAF headers to remote images being transformed', async (t)
cacheDir: '/tmp/ipx-cache',
bypassDomainCheck: true
}, (sourceImageOptions) => {
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['X-Nf-Waf-Bypass-Token'] === undefined)
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['x-nf-waf-bypass-token'] === undefined)

return Promise.resolve({ finalize: () => { } } as SourceImageResult)
})
Expand All @@ -144,7 +144,7 @@ test('should not add WAF headers to remote images being transformed', async (t)
{
rawUrl: 'http://localhost:3000/some-path',
path: '/_ipx/w_500/https%3A%2F%2Fsome-site.com%2Fno-file.jpg',
headers: { 'X-Nf-Waf-Bypass-Token': 'some token' },
headers: { 'x-nf-waf-bypass-token': 'some token' },
rawQuery: '',
httpMethod: 'GET',
queryStringParameters: {},
Expand All @@ -162,7 +162,7 @@ test('should not add WAF headers to local images if WAF is disabled', async (t)
cacheDir: '/tmp/ipx-cache',
bypassDomainCheck: true
}, (sourceImageOptions) => {
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['X-Nf-Waf-Bypass-Token'] === undefined)
t.assert(sourceImageOptions.requestHeaders && sourceImageOptions.requestHeaders['x-nf-waf-bypass-token'] === undefined)

return Promise.resolve({ finalize: () => { } } as SourceImageResult)
})
Expand Down

0 comments on commit 978f4c8

Please sign in to comment.