This repository was archived by the owner on Jul 31, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
fixed existing tests #19
Open
aarontravass
wants to merge
11
commits into
deno-libs:master
Choose a base branch
from
aarontravass:test/app
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a697a23
uncommented tests
aarontravass f0652e1
test: increased testing
aarontravass 81d6a27
fixed some tests
aarontravass 7195321
test: fixed more tests
aarontravass f90b3f1
test: fixed more tests
aarontravass 6317e79
Merge branch 'deno-libs:master' into test/app
aarontravass ca8be3a
test: fixed hanging test
aarontravass 2a10b39
fix: merged upstream master with test/app
aarontravass d40587e
fix hanging test
aarontravass 144e9ec
merged upstream master
aarontravass c368800
addressed comments
aarontravass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,31 @@ export type DownloadOptions = | |
headers: Record<string, unknown> | ||
}> | ||
|
||
type Callback = (err?: any) => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid |
||
|
||
export const download = < | ||
Req extends Request = Request, | ||
Res extends DummyResponse = DummyResponse, | ||
>(req: Req, res: Res) => | ||
async ( | ||
path: string, | ||
filename?: string, | ||
options: DownloadOptions = {}, | ||
filename?: string | Callback, | ||
options?: DownloadOptions | Callback, | ||
cb?: Callback, | ||
): Promise<Res> => { | ||
const name: string | null = filename as string | ||
let opts: DownloadOptions = options | ||
|
||
let name: string | null = filename as string | ||
let done = cb | ||
let opts: DownloadOptions = (options || null) as DownloadOptions | ||
if (typeof filename === 'function') { | ||
done = filename | ||
name = null | ||
} else if (typeof options === 'function') { | ||
done = options | ||
} | ||
opts = opts || {} | ||
// set Content-Disposition when file is sent | ||
const headers: Record<string, string> = { | ||
'Content-Disposition': contentDisposition(name || path), | ||
'Content-Disposition': contentDisposition(basename(name || path)), | ||
} | ||
|
||
// merge user-provided headers | ||
|
@@ -34,13 +44,16 @@ async ( | |
} | ||
} | ||
} | ||
|
||
// merge user-provided options | ||
opts = { ...opts, headers } | ||
|
||
// send file | ||
|
||
return await sendFile<Req, Res>(req, res)(path, opts) | ||
return await sendFile<Req, Res>(req, res)( | ||
path, | ||
opts, | ||
done || (() => undefined), | ||
) | ||
} | ||
|
||
export const attachment = | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,17 @@ export const sendFile = < | |
Req extends Request = Request, | ||
Res extends DummyResponse = DummyResponse, | ||
>(req: Req, res: Res) => | ||
async (path: string, { signal, ...opts }: SendFileOptions = {}) => { | ||
async ( | ||
path: string, | ||
{ signal, ...opts }: SendFileOptions = {}, | ||
cb?: (err?: any) => void, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better change it to |
||
) => { | ||
const { root, headers = {}, encoding = 'utf-8', ...options } = opts | ||
|
||
if (!_path.isAbsolute(path) && !root) { | ||
throw new TypeError('path must be absolute') | ||
} | ||
|
||
const filePath = root ? _path.join(root, path) : path | ||
|
||
const stats = await Deno.stat(filePath) | ||
|
||
headers['Content-Encoding'] = encoding | ||
|
@@ -48,7 +50,6 @@ async (path: string, { signal, ...opts }: SendFileOptions = {}) => { | |
|
||
headers['Content-Security-Policy'] = 'default-src \'none\'' | ||
headers['X-Content-Type-Options'] = 'nosniff' | ||
|
||
let status = 200 | ||
|
||
if (req.headers.get('range')) { | ||
|
@@ -74,7 +75,11 @@ async (path: string, { signal, ...opts }: SendFileOptions = {}) => { | |
|
||
res._init.status = status | ||
|
||
const file = await Deno.readFile(path, { signal }) | ||
let file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be instead wrapped in try catch |
||
await Deno.readFile(filePath, { signal }).then((f) => file = f).catch((e) => { | ||
cb!(e) | ||
file = null | ||
}) | ||
|
||
await send(req, res)(file) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--allow-all
is insecure to use. if you meant to add a permission add it via--allow-{perm}