Skip to content

Commit

Permalink
fixup! Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Sep 15, 2023
1 parent c99c8bd commit 75f62e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ function filterHeaders(allowedHeaders) {
*/
export class Server extends EventEmitter {
/**
* @param {Readonly<Options>} config
* @param {Readonly<Options>} options
*/
constructor(config) {
constructor(options) {
super()
if (!config.secret) {
if (!options.secret) {
throw new Error('secret is required')
}
this.config = {
...config,
serverName: config?.serverName || 'camo',
maxSize: config.maxSize || 100 * 1024 * 1024 // 100 MB
this.options = {
...options,
serverName: options.serverName || 'camo',
maxSize: options.maxSize || 100 * 1024 * 1024 // 100 MB
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ export class Server extends EventEmitter {
// TODO: respect forwarded headers (check if not private IP)
const filterRequestHeaders = filterHeaders(defaultRequestHeaders)
const filterResponseHeaders = filterHeaders(defaultResponseHeaders)
const client = new SafeHttpClient(this.config.maxSize)
const client = new SafeHttpClient(this.options.maxSize)
const {buffer, headers: resHeaders} = await client.safeFetch(validUrl, {
// @ts-expect-error: `IncomingHttpHeaders` can be passed to `Headers`
headers: filterRequestHeaders(new Headers(req.headers)),
Expand All @@ -130,7 +130,7 @@ export class Server extends EventEmitter {
const headers = {
...securityHeaders,
...filterResponseHeaders(resHeaders),
Via: this.config.serverName
Via: this.options.serverName
}

if (req.method === 'HEAD') {
Expand Down Expand Up @@ -164,7 +164,7 @@ export class Server extends EventEmitter {
const decodedUrl = Buffer.from(hex, 'hex').toString()

// Verify the HMAC digest to ensure the URL hasn't been tampered with
const hmac = crypto.createHmac('sha1', this.config.secret)
const hmac = crypto.createHmac('sha1', this.options.secret)
hmac.update(decodedUrl)
const expectedDigest = hmac.digest('hex')

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('camo', () => {
'https://avatars.githubusercontent.com/u/944406'
)
const res = await fetch(proxyUrl)
assert.strictEqual(res.status, 404)
assert.strictEqual(res.status, 413)
assert.strictEqual(await res.text(), 'Content-Length exceeded')
testDefaultHeaders(res)
})
Expand Down

0 comments on commit 75f62e7

Please sign in to comment.